Detecting two simultaneous keys in pyglet (python)

I wanted to know how to determine when two keys were pressed simultaneously using a piglet. I currently have

def on_text_motion (self, motion):
    (dx, dy) = ARROW_KEY_TO_VERSOR [motion]
    self.window.move_dx_dy ((dx, dy))

But these are only the arrow keys one at a time ... I would like to distinguish the combination of UP + LEFT and UP, then LEFT ...

I hope I made Mana clear

+3
source share
1 answer

Try pyglet.window.key.KeyStateHandler :

import pyglet

key = pyglet.window.key

win = pyglet.window.Window()
keyboard = key.KeyStateHandler()
win.push_handlers(keyboard)

print keyboard[key.UP] and keyboard[key.LEFT]
+4
source

Source: https://habr.com/ru/post/1715214/


All Articles