|
|
@@ -70,7 +70,7 @@ def _load_characters(data: dict) -> list:
|
|
|
return characters
|
|
|
|
|
|
|
|
|
-def simulate_key_press(key: [int, str], down: bool = True):
|
|
|
+def simulate_key_press(key: int | str, down: bool = True):
|
|
|
"""
|
|
|
Post a key press simulation to pygame event module.
|
|
|
|
|
|
@@ -93,6 +93,24 @@ def simulate_key_press(key: [int, str], down: bool = True):
|
|
|
pygame.event.post(key_event)
|
|
|
|
|
|
|
|
|
+def key_pressed(key: int | str) -> bool:
|
|
|
+ """
|
|
|
+ Check if a key has been pressed.
|
|
|
+
|
|
|
+ Parameters:
|
|
|
+ key: The key to be checked
|
|
|
+
|
|
|
+ Returns:
|
|
|
+ True if the key is pressed, False otherwise.
|
|
|
+
|
|
|
+ Examples:
|
|
|
+ >>> key_pressed('a')
|
|
|
+ False
|
|
|
+ """
|
|
|
+ key = utils.eval_key(key)
|
|
|
+ return _get_keys()[key]
|
|
|
+
|
|
|
+
|
|
|
def add_character(new_character: 'character.Character'):
|
|
|
"""
|
|
|
Add a new character to the videogame.
|