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

Can't detect question mark '?' from KeyEvent code (due to shift being pressed?) #2337

Open
totalgee opened this issue Dec 4, 2024 · 0 comments

Comments

@totalgee
Copy link
Contributor

totalgee commented Dec 4, 2024

When I press the question mark key '?' on the a keyboard (for different layouts, such as US English or Spanish), I never get the KeyEvent::KEY_QUESTION code, but a different one.

For example, in my keyDown() handler:

    if (event.getChar() == '?') {
        fmt::print("Got key: '{}' code: {} native: {} translated: {}", ch,
            event.getCode(),
            event.getNativeKeyCode(),
            KeyEvent::translateNativeKeyCode(event.getNativeKeyCode()));
    }

For a US English layout, I get this:
Got key: '?' code: 47 native: 191 translated: 47 -- this is '/', which is the unshifted key I'm pressing.
For a Spanish keyboard layout, I get this:
Got key: '?' code: 91 native: 219 translated: 91 -- this is '[', which is not the unshifted key; you would have ''' (apostrophe) on a Spanish keyboard as the unshifted '?' key.

The actual KeyEvent::KEY_QUESTION value is 63, which is also the ASCII value of '?'. But I never see that value as the "Cinder key code". I know I can (and do) just test the getChar() value, but it would be nice to be able to just use a single switch statement on the KeyEvent codes. I can't check event.isShiftDown() plus a different code in a compatible way, since the code is different for different layouts.

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

1 participant