Thanks for the heads up. To close this thread, here's the working
code:

from pyglet import window
from pyglet.window import key

class my_win(window.Window):
        def __init__(self, *args, **kwargs):
                self.done=False
                window.Window.__init__(self, *args, **kwargs)
        def on_key_press(self, symbol, modifiers):
                self.done=True

win=my_win()

while not win.done:
        win.dispatch_events()




On Jan 14, 3:44 pm, jimknopf <[EMAIL PROTECTED]> wrote:
> You can do this using the on_key_press event. For doing so, your
> window has to have the method on_key_press().
>
> I propose you take a look at this tutorial, which helped me a 
> lot:http://www.learningpython.com/2007/11/10/creating-a-game-with-pyglet-...
>
> The tutorial explains the on_mouse_press event. But the on_key_press
> event works more or less the same. Example:
>
> def on_key_press(self, symbol, modifiers):
>     if symbol == key.SPACE:
>         self.foo_bar()
>
> - Michael
>
> On 14 Jan., 19:28, Mike Lawrence <[EMAIL PROTECTED]> wrote:
>
> > Hi again,
>
> > Apologies for the simplicity of this one; I'm trying to simply detect
> > whether the space bar has been pressed and can't seem to get it right:
>
> > from pyglet import window
> > from pyglet.window import key
>
> > win=window.Window()
>
> > done=False
> > while not done:
> >         keys = key.KeyStateHandler()
> >         win.push_handlers(keys)
> >         if keys[key.SPACE]:
> >                 done=True
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to