glumpy icon indicating copy to clipboard operation
glumpy copied to clipboard

Inconsistent translation between GLFW and glumpy keycodes

Open hesom opened this issue 3 years ago • 1 comments

I'm trying to use keyboard inputs but I think the API is a bit unintuitive here. If I use the GLFW backend, the some keycodes returned by on_key_press are glfw keycodes but I would expect them to be the usual glumpy keycodes.

Minimal example:

import glfw
import glumpy
from glumpy import app

app.use("glfw")
window = app.Window(600, 600)

@window.event
def on_key_press(symbol, modifier):
    if symbol == glumpy.key.A:
        print("Glumpy A")

    if symbol == glfw.KEY_A:
        print("GLFW A")

    if symbol == glumpy.key.F1:
        print("Glumpy F1")

    if symbol == glfw.KEY_F1:
        print("GLFW F1")

app.run()

If you run this code and press the A key I would expect the output to be "Glumpy A" but it is "GLFW A" instead. More confusingly, when you press the F1 key the keycode seems to be correctly translated to glumpy and the output is "Glumpy F1". This seems inconsistent to me.

I could extend the key map in backend_glfw.py and make a PR, but I first wanted to know if this is intended behaviour

hesom avatar May 16 '22 11:05 hesom

There are actually two events for keyboard: on_key_press and on_character. The first one ise used to read the keyboard code while the second is used to read the pressed character (when it is a character).

rougier avatar May 20 '22 18:05 rougier