I would like to know if exists any possibility to get the 'real' ASCII code for pressed key.
When I press key 'A' without any modifiers (like shift,alt ...) the key event.GetCode() have return 65 and all modifiers are set off. I know that should be ' 97 ' = 'a' and in this case isn't a problem.
The problem is when I press ' 2 ' (ASCII 50) + shift it should be '@' (ASCII 64) , the modifier m_shiftDown ist set on, but how should I know that it is '@' . I can't assign 2 + shift to @, because this is depended on keyboard setting , language setting etc.
Is it possible to make something like event.Veto() in event EVT_KEY_UP ?
In event EVT_KEY_DOWN return from function without event.Skip() works and stops the actions on the lowers levels , but doesn't work in EVT_KEY_UP and the actions from the lowers levels are executed.
I found that a combination of str() and ord() satisfies most (not all)
of my ASCII troubles. I attach a piece of (possibly very stupip) code -
hope it helps.
def OnChar(self, evt):
"""
a handler to make all keys uppercase
"""
key = evt.KeyCode()
if key < WXK_SPACE or key == WXK_DELETE or key > 255:
evt.Skip()
return
key = chr(key)
if self.toupper and key in string.lowercase:
key = string.upper(key)
evt.m_keyCode = ord(key)
evt.Skip()
···
On Sat, 2003-09-06 at 14:14, Artur Kapela wrote:
Hi, everybody.
Windows Xp, Python 2.2.3, wxPython 2.4.1.2
I would like to know if exists any possibility to get the 'real' ASCII
code for pressed key.
When I press key 'A' without any modifiers (like shift,alt ...) the
key event.GetCode() have return 65 and all modifiers are set off. I
know that should be ' 97 ' = 'a' and in this case isn't a problem.
The problem is when I press ' 2 ' (ASCII 50) + shift it should be '@'
(ASCII 64) , the modifier m_shiftDown ist set on, but how should I know
that it is '@' . I can't assign 2 + shift to @, because this is
depended on keyboard setting , language setting etc.
Is it possible to make something like event.Veto() in event EVT_KEY_UP
?
In event EVT_KEY_DOWN return from function without event.Skip() works
and stops the actions on the lowers levels , but doesn't work in
EVT_KEY_UP and the actions from the lowers levels are executed.
Thanks for any comments.
Artur.
--
Thys Meintjes
BEng Electronic (UP), MEng Bio (UP)
Intrepid Investigator of Interesting Things
+27 82 3764 602
I would like to know if exists any possibility to get the 'real'
ASCII code for pressed key.
When I press key 'A' without any modifiers (like shift,alt ...) the
key event.GetCode() have return 65 and all modifiers are set off. I
know that should be ' 97 ' = 'a' and in this case isn't a problem.
It depends on the event you catch. EVT_KEY_DOWN and _UP will give you
raw key values while EVT_CHAR will give you "cooked" values with the
modifiers applied.
Is it possible to make something like event.Veto() in event
EVT_KEY_UP ? In event EVT_KEY_DOWN return from function without
event.Skip() works and stops the actions on the lowers levels , but
doesn't work in EVT_KEY_UP and the actions from the lowers levels are
executed.
Actually, they are probably handled in the native EVT_KEY_DOWN or
EVT_CHAR handlers...
The way wxWindows works is that if you handle EVT_KEY_DOWN and don't
call Skip then there will not be a EVT_CHAR generated for the key. Play
with the wxKeyEvent sample in the demo to get a better feel for things.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!