Confused about GetKeyCode()/GetUnicodeKey()

Robin Dunn robin at alldunn.com
Sat Nov 3 12:13:55 PDT 2007


Vadim Zeitlin wrote:
> On Sat, 3 Nov 2007 15:31:03 +0000 Richard Danter <radanter at googlemail.com> wrote:
> 
> RD> I am trying to write a keyboard event handler and I am a little
> RD> confused which method I should use to get the key code. I think I
> RD> should use GetUnicodeKey() since I have a Unicode build,
> 
>  This rather works in the other direction -- if you a Unicode build, you
> may use GetUnicodeKey() to get key presses for non-ASCII characters. But
> nothing prevents you from using GetKeyCode() to handle arrow keys.
> 
> RD> For the most part I can use GetKeyCode() OK, but I lose the ability to
> RD> enter the Euro symbol (AltGr+4 on my UK keyboard), which works fine if
> RD> I use GetUnicodeKey().
> 
>  I'm not sure about what does GetKeyCode() return for the Euro key but
> normally you should simply check for the special WXK_XXX values first using
> GetKeyCode() and if there is no match use GetUnicodeKey() to get the key
> value.

The advice I usually people to use GetKeyCode for KEY_DOWN/_UP events, 
and GetUnicodeKey for EVT_CHAR events, and to divide their program 
functionality into the two camps as well.  Anytime they want to react to 
certain keys being pressed (F-keys, arrow keys, hot-keys, anything where 
it is the raw *key* that matters) then they should do it in the 
KEY_DOWN/_UP events.  On the other hand, anytime you are interested in 
*text* then you should be using the EVT_CHAR events because that is 
where the raw key events will have been cooked using whatever recipes 
are in effect from the os, locale, international keyboard settings, 
IMEs, etc. and is where the unicode value will matter.


-- 
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!





More information about the wx-users mailing list