The KeyStateHandler can take care of some of this logic automatically. This is from the docs:
# http://pyglet.readthedocs.io/en/pyglet-1.2-maintenance/programming_guide/keyboard.html#remembering-key-state from pyglet.window import key window = pyglet.window.Window() keys = key.KeyStateHandler() window.push_handlers(keys) # Check if the spacebar is currently pressed: if keys[key.SPACE]: pass On 04/26/2017 04:39 PM, [email protected] wrote: > Whenever a key is pressed functions like on_key_press are automatically > called, > but only when a key is pressed or released. Its usually best to use this to > toggle other variables you can use in your main loop, as a simple example: > > | > right =False > left =False > x =0 > speed =0.5 > > #main loop > defupdate(dt): > ifright ==True: > x +=speed > ifleft ==True: > x -=speed > > defon_key_press(symbol,modifiers): > ifsymbol ==key.RIGHT: > right =True > ifsymbol ==key.LEFT: > left =True > > defon_key_release(symbol,modifiers): > ifsymbol ==key.RIGHT: > right =False > ifsymbol ==key.LEFT: > left =False > | > > > -- > You received this message because you are subscribed to the Google Groups > "pyglet-users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email > to [email protected] > <mailto:[email protected]>. > To post to this group, send email to [email protected] > <mailto:[email protected]>. > Visit this group at https://groups.google.com/group/pyglet-users. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "pyglet-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/pyglet-users. For more options, visit https://groups.google.com/d/optout.
