Browse Source

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

master
Bryan Miller 6 years ago
parent
commit
a156804a52
2 changed files with 6 additions and 6 deletions
  1. +3
    -3
      game/__init__.py
  2. +3
    -3
      game/gbe/events.py

+ 3
- 3
game/__init__.py View File

if event == "KEYDOWN": if event == "KEYDOWN":
if data["key"] == 27: if data["key"] == 27:
_RUNNING = False _RUNNING = False
print("Key {} down".format(data["key"]))
print("Key {} down".format(data["key_name"]))
elif event == "KEYUP": elif event == "KEYUP":
print("Key {} up".format(data["key"]))
print("Key {} up".format(data["key_name"]))
elif event == "KEYPRESSED": elif event == "KEYPRESSED":
print("Key {} pressed".format(data["key"]))
print("Key {} pressed".format(data["key_name"]))







+ 3
- 3
game/gbe/events.py View File

lastTick = k[1] lastTick = k[1]
_DOWNKEYS.remove(k) _DOWNKEYS.remove(k)
if tick - lastTick <= _ClickDelayMax: 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. return # Done.
# We found nothing, boss. # We found nothing, boss.


Events.emit("QUIT", {}) Events.emit("QUIT", {})
elif event.type == pygame.KEYDOWN: elif event.type == pygame.KEYDOWN:
_WatchKey(event.key) _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: 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) _ReleaseKey(event.key)
elif event.type == pygame.MOUSEMOTION: elif event.type == pygame.MOUSEMOTION:
Events.emit("MOUSEMOTION", {"pos":event.pos, "rel":event.rel, "buttons":event.buttons}) Events.emit("MOUSEMOTION", {"pos":event.pos, "rel":event.rel, "buttons":event.buttons})

Loading…
Cancel
Save