I am making a program in which a keyboard event handler is created and
gets destroyed after 5 seconds.

Here is the code:

import pyglet

class App(pyglet.window.Window):
    def __init__(self):
        super(App, self).__init__()
        self.set_on()

    def set_on(self):
        print "on"
        self.set_handler("on_key_press", self.register)

        # Makes sure it gets set off after 5 minutes
        pyglet.clock.schedule_once(self.set_off, 5)

    def set_off(self, dt):
        print "off"
        self.remove_handler("on_key_press", self.register)

    def register(self, symbol, modifiers):
        print "keypress"

app = App()
pyglet.app.run()

Here is what happens when I use the program:
on
keypress
keypress
keypress
keypress
keypress
off
keypress
keypress
keypress
keypress
keypress

As you see there are keypresses that get handled even after I remove
the event handler for keypresses.
I could work around it by using an ifstatement in the event handler,
but I still think this is weird behaviour.

Also, this problem might be related:
http://groups.google.com/group/pyglet-users/browse_thread/thread/5040cbc18a813dc3#

-- 
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