瀏覽代碼

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

master
Bryan Miller 6 年之前
父節點
當前提交
a156804a52
共有 2 個文件被更改,包括 6 次插入6 次删除
  1. +3
    -3
      game/__init__.py
  2. +3
    -3
      game/gbe/events.py

+ 3
- 3
game/__init__.py 查看文件

@@ -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 查看文件

@@ -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})

Loading…
取消
儲存