tags:

views:

68

answers:

3

I am writing a small sample program and I would like to override the default pyglet's behavioyr of ESC closing the app. I have something to the extent of:

window = pyglet.window.Window()
@window.event
def on_key_press(symbol, modifiers):
    if symbol == pyglet.window.key.ESCAPE:
        pass

but that does not seem to work.

+1  A: 

On the Google group for pyglet-users it is suggest could overload the window.Window.on_key_press(), although there are no code example of it.

Alastair
+2  A: 

I know the question is old, but just in case. You've got to return pyglet.event.EVENT_HANDLED to prevent default behaviour. I didn't test it, but in theory this should work:

@window.event
def on_key_press(symbol, modifiers):
    if symbol == pyglet.window.key.ESCAPE:
        return pyglet.event.EVENT_HANDLED
Imbrondir
A: 

Same for me. Question is old, but i've found that you should use window handlers mechanisms, thus making current event not to propagate further.

You can prevent the remaining event handlers in the stack from receiving the event by returning a true value. The following event handler, when pushed onto the window, will prevent the escape key from exiting the program:

def on_key_press(symbol, modifiers):
    if symbol == key.ESCAPE:
        return True

window.push_handlers(on_key_press)

Here is that link

varnie