nodebox/nodebox-opengl

Wrong key code in on_key_press()

ont opened this issue · 2 comments

ont commented

Default on_key_press doesn't react on ESC. If I change code to this variant:

def on_key_press(self, keys):
    """ The default behavior of the canvas:
        - ESC exits the application,
        - CTRL-P pauses the animation,
        - CTRL-S saves a screenshot.
    """
    print '--->', keys.code, type( keys.code )
    if keys.code == ESCAPE:
        self.stop()
    if keys.code == "p" and CTRL in keys.modifiers:
        self.paused = not self.paused
    if keys.code == "s" and CTRL in keys.modifiers:
        self.save("nodebox-%s.png" % str(datetime.now()).split(".")[0].replace(" ","-").replace(":","-"))

... then I get this output:

---> 65307 <type 'long'>

So why ESCAPE was defined as ESCAPE = "escape" ?

My pyglet.version == '1.1.4'

ont commented

Possible solution. Change code in nodebox/graphics/context.py

from numbers      import Number
...
class Keys(list):
...
    def _decode(self, code):
        if not isinstance(code, Number):
            s = code
        else:
            s = pyglet.window.key.symbol_string(code)         # 65288 => "BACKSPACE"

On my system type(code) == <type 'long'> and not <type 'int'>

ont commented

Please see pull request #6