Cinder
Cinder copied to clipboard
Can't detect question mark '?' from KeyEvent code (due to shift being pressed?)
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.
Related to your old issue? https://github.com/cinder/Cinder/issues/2194 I mean I guess what you expose now is the reason behind your old post.
Sort of related, but not exactly the same issue. I think this issue is just the way things are... I suppose the "proper" way to deal with different keyboard layouts is to allow a way for the user to make their own mapping of keys to functionality, so if it's wrong, they can adjust it as desired. Or, in my case if I really want to check for '?', just I'll use event.getChar() for some that and similar cases, and use event.getCode() for others.