Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent translation between GLFW and glumpy keycodes #299

Open
hesom opened this issue May 16, 2022 · 1 comment
Open

Inconsistent translation between GLFW and glumpy keycodes #299

hesom opened this issue May 16, 2022 · 1 comment

Comments

@hesom
Copy link
Contributor

hesom commented May 16, 2022

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

@rougier
Copy link
Member

rougier commented May 20, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants