Przeglądaj źródła

For the KEYDOWN/UP/PRESSED events, added a 'key_name' variable with the name of the key pressed.

master
Bryan Miller 6 lat temu
rodzic
commit
a156804a52
2 zmienionych plików z 6 dodań i 6 usunięć
  1. +3
    -3
      game/__init__.py
  2. +3
    -3
      game/gbe/events.py

+ 3
- 3
game/__init__.py Wyświetl plik

@@ -18,11 +18,11 @@ def _OnKeyEvent(event, data):
if event == "KEYDOWN":
if data["key"] == 27:
_RUNNING = False
print("Key {} down".format(data["key"]))
print("Key {} down".format(data["key_name"]))
elif event == "KEYUP":
print("Key {} up".format(data["key"]))
print("Key {} up".format(data["key_name"]))
elif event == "KEYPRESSED":
print("Key {} pressed".format(data["key"]))
print("Key {} pressed".format(data["key_name"]))




+ 3
- 3
game/gbe/events.py Wyświetl plik

@@ -81,7 +81,7 @@ def _ReleaseKey(key):
lastTick = k[1]
_DOWNKEYS.remove(k)
if tick - lastTick <= _ClickDelayMax:
Events.emit("KEYPRESSED", {"key":key, "mod":pygame.key.get_mods()})
Events.emit("KEYPRESSED", {"key":key, "mod":pygame.key.get_mods(), "key_name":pygame.key.name(key)})
return # Done.
# We found nothing, boss.

@@ -121,9 +121,9 @@ def pollEmitter():
Events.emit("QUIT", {})
elif event.type == pygame.KEYDOWN:
_WatchKey(event.key)
Events.emit("KEYDOWN", {"unicode":event.unicode, "key":event.key, "mod":event.mod})
Events.emit("KEYDOWN", {"unicode":event.unicode, "key":event.key, "mod":event.mod, "key_name":pygame.key.name(event.key)})
elif event.type == pygame.KEYUP:
Events.emit("KEYUP", {"key":event.key, "mod":event.mod})
Events.emit("KEYUP", {"key":event.key, "mod":event.mod, "key_name":pygame.key.name(event.key)})
_ReleaseKey(event.key)
elif event.type == pygame.MOUSEMOTION:
Events.emit("MOUSEMOTION", {"pos":event.pos, "rel":event.rel, "buttons":event.buttons})

Ładowanie…
Anuluj
Zapisz