But, it does not work with russian layout on (at least in linux, with wxwidgets 4.0.6). Russian “Ф” is on the same key as english “A”. GetKeyCode() returns 0 for that, just like intended according to docs. GetUnicodeKey() returns 1092.
How do I detect if “A” key has been pressed regardless of current active layout?
I would expect the EVT_KEY_UP event to be the same, but you may have better luck using the EVT_KEY_DOWN event. The idea behind these events is that the key-up and -down events deal with the “raw” hardware-level events and the same physical keys should give the same values regardless of active language and layout. On the other hand, the EVT_CHAR event should give the “cooked” values that have been modified for layout, IMEs or whatever. It sounds like the key-up event is giving you the cooked values, so maybe the key-down events will be better for your use case. However, it is possible for the platform or IMEs to not strictly follow this pattern and there isn’t anything wx can do about that if that is the case.
Also, the wx.KeyEvent inherits from wx.KeyboardState so there is no need to use wx.GetMouseState to get the current state of the modifiers. You can use the event to get them at the time that the key was pressed. (It’s unlikely but it’s possible for the modifiers to change between the keypress and the time you call wx.GetMoustState.)
Key up works the same way for me. They return code 65 when I press “a” (which is ASCII code for “A”, regardless of caps lock state, which is to be expected), and 0 when i press the same button with russian layout active.
While GetKeyCode also returns the character code for Latin-1 keys for compatibility, it doesn’t work for Unicode characters in general and will return WXK_NONE for any non-Latin-1 ones.
In wxwidget mailing list I’ve got suggestion to use GetRawKeyCode() and GetRawKeyFlags(), so i guess i will have to look into that.