views:

205

answers:

1

Hi there... I wanted to know how to detect when two keys are simultaneously pressed using pyglet. I currently have

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

But this only gets arrow keys one at a time... I'd like to distinguish between the combination UP+LEFT and UP, then LEFT...

Hope I made myself clear Manu

+3  A: 

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]
Karl Voigtland