How to handle unicode keys in wx.EVT_CHAR ?

Hello everybody,

I do have some problems regarding the EVT_CHAR event. I'm getting
different events for the same keys on my WXMSW, WXGTK and WXMAC. My
question now is: is this a bug, or do I have to change my code ?

I've written a short piece of sample code I've used for my test. On each
platform I'm pressing these keys: "a", AltGr-E (Euro-Symbol), F1 and
Ctrl-a.

This is the sample-Code:

import wx

def OnKeyPress (event):
  print "KC:", event.GetKeyCode (), "UC:", event.GetUnicodeKey ()
  event.Skip ()

app = wx.PySimpleApp ()

f = wx.Frame (None)
e = wx.TextCtrl (f, -1)
e.Connect (-1, -1,wx.wxEVT_CHAR, OnKeyPress)
e.SetFocus ()
f.Fit ()
f.Show ()

app.MainLoop ()

And these are the results (all installations are unicode-versions):

On WXGTK 2.6.1.1.pre:

KC: 97 UC: 97
KC: 342 UC: 0
KC: 97 UC: 97

On WXMSW 2.6.1.1:

KC: 97 UC: 97
KC: 8364 UC: 8364
KC: 342 UC: 112
KC: 1 UC: 1

On WXMAC 2.5.3.1:

KC: 97 UC: 0
KC: 219 UC: 0
KC: 342 UC: 0
KC: 1 UC: 0

Q: Why is there *NO* EVT_CHAR event for AltGr-E on WXGKT, although the
proper Euro symbol appears in the entry widget ???

Q: Why is there a different KeyCode and UnicodeKey for F1 on WXMSW ?

Q: Why is the UnicodeKey on WXMAC always 0 ?

Can you please give me some help ?

Thanks in adavance,

Johannes

···

--
BYTEWISE Software GmbH Tel +43 (5577) 89877-0
i.A. Johannes Vetter Fax +43 (5577) 89877-66
A-6890 Lustenau, Enga 2 http://www.bytewise.at
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Wir bieten Installation und Support für Ubuntu: ein auf
GNU/Linux basierendes Softwaresystem für Arbeitsplatzrechner

Johannes Vetter wrote:

Hello everybody,

I do have some problems regarding the EVT_CHAR event. I'm getting
different events for the same keys on my WXMSW, WXGTK and WXMAC. My
question now is: is this a bug, or do I have to change my code ?

There are a couple bugs here, and I've raised the issues on wx-dev. But there will also be some inconsistencies between the platforms as far as actually inputting the special characters that will depend on locale settings and also how each platform maps the keyboard layout.

Q: Why is there *NO* EVT_CHAR event for AltGr-E on WXGKT, although the
proper Euro symbol appears in the entry widget ???

Interestingly enough, I get the EVT_CHAR for the Euro, but no EVT_KEY_DOWN or _UP.

Q: Why is there a different KeyCode and UnicodeKey for F1 on WXMSW ?

The unicode value is a copy of the RawKeyCode(), but the keyCode value being set for the Function Keys happens elsewhere.

Q: Why is the UnicodeKey on WXMAC always 0 ?

What version of wxPython are you using?

Can you please give me some help ?

I do something like this in one of my apps, maybe it will help. Basically it falls back to the keyCode value if the UnicodeKey value is < 127:

  key = evt.GetUnicodeKey()

  # If the unicode key code is not really a unicode character (it may
  # be a function key or etc., the platforms appear to always give us a
  # small value in this case) then fallback to the ascii key code
  if key < 127:
    key = evt.GetKeyCode()

  # Do something with key

···

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

Hi,

> Q: Why is there *NO* EVT_CHAR event for AltGr-E on WXGKT, although
the
> proper Euro symbol appears in the entry widget ???

Interestingly enough, I get the EVT_CHAR for the Euro, but no
EVT_KEY_DOWN or _UP.

Hm, that's really strange ... I'm using wx 2.6.1.1.pre on Ubuntu 5.10
(LANG=de_AT.UTF-8). Should I go and get a newer wx version ? Can I do
anything to get an EVT_CHAR for AltGr-E ?

>
> Q: Why is there a different KeyCode and UnicodeKey for F1 on WXMSW ?

The unicode value is a copy of the RawKeyCode(), but the keyCode
value
being set for the Function Keys happens elsewhere.

Hm, on WXMAC and WXGTK the UnicodeKey for all the function keys is 0.
This would make it easy to find out, wether the key is a 'printable'
character or a function key. But since I never get a UnicodeKey other
than 0 on WXMAC this isn't really reliable. Is there a reliable way to
distinguish between a function key (WXK_*) and a 'printable' character ?

>
> Q: Why is the UnicodeKey on WXMAC always 0 ?

What version of wxPython are you using?

On my Mac I'm using Tiger's builtin wx 2.5.3.1

There are a couple bugs here, and I've raised the issues on wx-dev.

Are there any foreseeable fixes in the near future ?

Thanks a lot,

Johannes

···

Am Montag, den 30.01.2006, 15:31 -0800 schrieb Robin Dunn:

--
BYTEWISE Software GmbH Tel +43 (5577) 89877-0
i.A. Johannes Vetter Fax +43 (5577) 89877-66
A-6890 Lustenau, Enga 2 http://www.bytewise.at
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Wir bieten Installation und Support für Ubuntu: ein auf
GNU/Linux basierendes Softwaresystem für Arbeitsplatzrechner

Johannes Vetter wrote:

Hi,

Q: Why is there *NO* EVT_CHAR event for AltGr-E on WXGKT, although

the

proper Euro symbol appears in the entry widget ???

Interestingly enough, I get the EVT_CHAR for the Euro, but no EVT_KEY_DOWN or _UP.

Hm, that's really strange ... I'm using wx 2.6.1.1.pre on Ubuntu 5.10
(LANG=de_AT.UTF-8). Should I go and get a newer wx version ? Can I do
anything to get an EVT_CHAR for AltGr-E ?

Definitely try a new version, but there could still be some issues around what the platform is giving you based on the input methods and keyboard layout settings, so you may want to try doign some experimentation there too.

Q: Why is there a different KeyCode and UnicodeKey for F1 on WXMSW ?

The unicode value is a copy of the RawKeyCode(), but the keyCode
value being set for the Function Keys happens elsewhere.

Hm, on WXMAC and WXGTK the UnicodeKey for all the function keys is 0.
This would make it easy to find out, wether the key is a 'printable'
character or a function key. But since I never get a UnicodeKey other
than 0 on WXMAC this isn't really reliable. Is there a reliable way to
distinguish between a function key (WXK_*) and a 'printable' character ?

Q: Why is the UnicodeKey on WXMAC always 0 ?

What version of wxPython are you using?

On my Mac I'm using Tiger's builtin wx 2.5.3.1

You'll definitely want to try a new version on Mac as well. There has been a number of improvements on wxMac since 2.5.3.

There are a couple bugs here, and I've raised the issues on wx-dev.

Are there any foreseeable fixes in the near future ?

Yes.

···

Am Montag, den 30.01.2006, 15:31 -0800 schrieb Robin Dunn:

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