Modifiers and key events

I don't understand how modifier keys and WX key events interact. If I
print out event.GetKeyCode() and event.GetModifiers(), I get these
results:

numpad-6: 330 0
shift + numpad-6: 330 4
ctrl + numpad-6: 330 16
'a': 97 0
shift + 'a': 65 4
ctrl + 'a': 1 16
6: 54
shift + 6: 94 4
ctrl + 6: no key event received

It doesn't bug me so much that hitting Shift modifies the ASCII code
that GetKeyCode() returns, but what the heck is going on when Control
is pressed?

Is there some way to get the "base key" that was pressed, with the
modifiers alongside?

-Chris

This is sensible enough as 'a'=a but shift-'a'=A as will caps-lock on
then 'a' and '6'=6 but shift-'6'=^, (depending on your keyboard
mapping). This because you are looking for the "character" pressed
rather than the key so the keyboard mappings and modifiers are used.

If you bind to wx.EVT_KEY_DOWN instead of to wx.EVT_CHAR then you will
get the raw keyboard key pressed according to the documentation.

Gadget/Steve

···

On 13/10/2012 11:16 PM, Chris Weisiger wrote:

I don't understand how modifier keys and WX key events interact. If I
print out event.GetKeyCode() and event.GetModifiers(), I get these
results:

numpad-6: 330 0
shift + numpad-6: 330 4
ctrl + numpad-6: 330 16
'a': 97 0
shift + 'a': 65 4
ctrl + 'a': 1 16
6: 54
shift + 6: 94 4
ctrl + 6: no key event received

It doesn't bug me so much that hitting Shift modifies the ASCII code
that GetKeyCode() returns, but what the heck is going on when Control
is pressed?

Is there some way to get the "base key" that was pressed, with the
modifiers alongside?

-Chris

Chris Weisiger wrote:

I don't understand how modifier keys and WX key events interact. If I
print out event.GetKeyCode() and event.GetModifiers(), I get these
results:

numpad-6: 330 0
shift + numpad-6: 330 4
ctrl + numpad-6: 330 16
'a': 97 0
shift + 'a': 65 4
ctrl + 'a': 1 16
6: 54
shift + 6: 94 4
ctrl + 6: no key event received

It doesn't bug me so much that hitting Shift modifies the ASCII code
that GetKeyCode() returns, but what the heck is going on when Control
is pressed?

"Ctrl-A" has a well-defined value in ASCII -- 1. All of the alpha
characters have a defined Ctrl value. The digits do not. For your
numeric keypad, you must have had NumLock off. In that case, you're
actually getting the extended code for "right arrow", which is outside
the ASCII world to begin with.

If you just want raw key number and modifiers, without the ASCII
interpretation, Steve's advice is the right advice.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

Also, playing with the KeyEvents sample in the demo can be helpful for learning how things work. It shows details for EVT_CHAR, EVT_KEY_DOWN and EVT_KEY_UP events and lets you turn them on or off, etc.

···

On 10/15/12 10:56 AM, Tim Roberts wrote:

Chris Weisiger wrote:

I don't understand how modifier keys and WX key events interact. If I
print out event.GetKeyCode() and event.GetModifiers(), I get these
results:

numpad-6: 330 0
shift + numpad-6: 330 4
ctrl + numpad-6: 330 16
'a': 97 0
shift + 'a': 65 4
ctrl + 'a': 1 16
6: 54
shift + 6: 94 4
ctrl + 6: no key event received

It doesn't bug me so much that hitting Shift modifies the ASCII code
that GetKeyCode() returns, but what the heck is going on when Control
is pressed?

"Ctrl-A" has a well-defined value in ASCII -- 1. All of the alpha
characters have a defined Ctrl value. The digits do not. For your
numeric keypad, you must have had NumLock off. In that case, you're
actually getting the extended code for "right arrow", which is outside
the ASCII world to begin with.

If you just want raw key number and modifiers, without the ASCII
interpretation, Steve's advice is the right advice.

--
Robin Dunn
Software Craftsman