Robin Dunn wrote:
Will Sadkin wrote:
Aha. That's the answer then; the cyrillic char's keycode is not in
the range 32-255, and so the above code assumes that it's a
control-key of some sort, and so allows it to "go through" to the
base control, a standard wx.TextCtrl. This causes it to be inserted
into the control text, which is not supposed to happen with a
printable character in a masked control; the masked control logic is
supposed to be responsible for all characters inserted into the
control's contents. (Hence all the problems.)Will, you can easily reproduce this yourself with a regular US English
keyboard. Just install the language packs (see Regional and Language
Options in the XP Control Panel) including the keyboard services for
the language. Then you can switch keyboard layouts on the fly via the
taskbar tool. For example I can duplicate the problem using a French
keyboard layout and typing €, which is accessed by using the
right-side Alt key (aka AltGr) and pressing e.
Good to know.
What would be a more correct test instead of the one above, ie.
"if key < wx.WXK_SPACE or key > 255:", that would work universally
across all locales to ensure that I'm not passing visible characters
to the base control? Or is my analysis flawed somehow? (I must
confess that I've done very little with unicode at all, and so feel
out of my depth here...)You also want to look at the event.GetUnicodeKey() value if you're
running in a Unicode build. There is no solid rule for it, but I have
found that if that value is > 127 then you can safely use that value
instead of GetKeyCode(), (unless you are actually looking for a
function key or something else that maps into that range of key code
values. )
The point of the test is to "redirect" all (remaining) non-printable
keystrokes to the base control. I don't think that I care what the
unicode key value is at that point; I just want to know if the key
typed is "printable" ie. would show up in the underlying text
control. As Chris Mellon pointed out, there is nothing like
string.printable for unicode, so I need a better test.
Given your response, unless GetUnicodeKey() gives you something
like None on a non-printable char, I'm tempted to take Chris'
suggestion, and just explicitly test for the known control characters.
Reading the wxKeyEvent doc, I'd build an array in the maskededit
class of all the keycodes mentioned in that doc (I don't see one
that already exists), plus all the control keys below wx.WXK_SPACE,
and then just say:
if key in wx_unprintable_keycodes:
# pass to the base control
event.Skip()
(This seems safer.)
But there's one other issue raised by this discussion...
Currently, the * mask char is allowed to represent "any ansi
character", ie keycode values between 32 and 256. I had thought
that would also mean any visible character, which is what I
*wanted* * to mean, but again, clearly this is not the case.
The control works by matching an explicit list of characters to
each mask character type. So I would still like a way to say
"all visible chars" (unicode or not.) How do I get this list
of characters?
/Will