EVT_KEY_UP and non-english keyboard layout

I have ListCtrl and I want to be able to detect if user has pressed Ctrl-A to select all items in the list. I have following code:

    def __init__(self, parent):
        self.Bind(wx.EVT_KEY_UP, self.kbEvent)

    def kbEvent(self, event):
        keycode = event.GetKeyCode()
        mstate = wx.GetMouseState()
        elif keycode == 65 and mstate.GetModifiers() == wx.MOD_CONTROL:

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.

Following sentence hinted me that it might be by design:

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.

Just found out that it works under Windows. So, i guess, it is linux-only issue. Will check it under Mac later.

Decided to fill a ticket to cover it: https://github.com/wxWidgets/Phoenix/issues/1391