Character code and keyboards under Windows
Character Set
basically, Windows uses the ANSI character set and not the 8-bits ASCII char set. The ANSI char set contains 255 chars. To enter a char, the user hits a key or a combination of keys (SHIFT, CTRL, ...). He (She) can also use the alt+0nnn command, where nnn represents the ANSI code of The char set. To use this command, keep the ALT key down and enter the char code from the Numeri C pad, numlock being on. Examples:in order to get the char A, I can hits the a key on my keyboard or I can Enter the command alt+097.
To obtain a E acute, one can use the alt+0233 command; For a n tilde, I use alt+241; For an angstroem, alt+0229. ALT+0NNN is working for every kbd (US or not us).
The European chars is in the range 128..255 of the ANSI char set.
Keyboards
every language have its own keyboard. The system provides a keyboard/language "Driver" for every language. Roughly speaking, when the user hits a key or a combination of keys, the keyboard/ Language driver translates the ' pressed Keys ' into an alt+0nnn char code.
some more examples coming from my Swiss French keyboard: in Order to get a ' a ', I-hit the a key or I may enter the alt+097 command. to get the A, I press shift+a or I enter the command alt+065. To get the A # char (comment char in Python), I should press ctrl+alt+3. A} is obtained by ctrl+alt+$ or by the command alt+0125.
pressing simultaneously three keys are not very pratical. That the reason why on European keyboards we have a key called AltGr. AltGr is nothing else than Ctrl and Alt used Simultaneoulsy. So in my example, if I want to get the # Char, I can press ctrl+alt+3, altgr+3 or Enter the command alt+035. AltGr can be see as a ' super shift ' or as ' one another shift ' key.
on a US keyboard, you can be not type directly an e acute, you have to enter the command alt+0233. (Yes, I installed a US KBD and tested it under windows, this can is done in 2 min Utes)
Things can even a litte bit more complicated with the so called Dead keys. What is a dead key? When you press a dead key, the caret would not move. It would move only after a Secong key had been pressed. Example:on My Swiss French keyboard, I can not enter directly an e circumflex. The circumflex key which is a dead key. In order to obtain a E Cicumflex, I hit the circumflex key, the Carret was not moving, then I hit the E Key and the E Circumlflex appears on my screen. An alternative-on-the-alt+0234 command.
Python Coding using WxPython
What can go wrong within (WX) Python? I see both problems.
1. It seems that some WxPython (wxwindows?) Ctrls is using only the first
- Half of the ANSI char set. That is means only a 7 bits char code. (The first half of the ANSI char set is identical to the 7-bits ASCII char set).
2. We have seen that AltGr = Ctrl + Alt. So if your application needs to
Below An example showing how pressed key (s) is handled correcly. From shell.py, Pycrust, available in the demo. I deleted some lines.
def OnKeyDown (self, event): ' "" Key down event handler. ... Key = event. KeyCode () Controldown = event. Controldown () Altdown = event. Altdown () Shiftdown = event. Shiftdown () currpos = self. Getcurrentpos () endpos = self. Gettextlength () # Return (Enter) is used to submit a command to the interpreter. If not controldown and key = = Wxk_return: ... Self.processline () # If The Auto-complete window is up let it does its thing. Elif self. Autocompactive (): ... Event. Skip () # Let ctrl-alt-* get handled normally. Elif Controldown and Altdown: event. Skip () ... ... # Cut to the Clipboard. Elif (Controldown and Key in (Ord (' X '), Ord (' X '))) or (shiftdown and key = = Wxk_delete): Self . Cut () ... ... # Insert the next command from the history buffer. Else: event. Skip ()
The lines of code
Elif Controldown and Altdown: event. Skip ()
Let European people use smoothly their AltGr keys.
Char codes and key codes
Char codes and key codes are different things. The method event. KeyCode () Returns a key code, not a char code. The left arrow had a key code but no char code.
The char Issue:python, wxPython or UNICODE problem?
I don ' t know. Using pycrust under Windows, you can test the following code:
>>> for I in range (255): ... Print I, Chr (i)
You'll see, that's obtain (correcly) all the ANSI chars. Note:if You try the same test using IDLE, you don ' t Get the same result. This is normal, Chr () would return a char based on the 8-bits ASCII char set (DOS).
Is my fonts updated?
This could sound stupid, but the TTF font files has changed. Try the following key combination ctrl+alt+e or Altgr+e or alt+0128. You should obtain the euro char, the new currency unit symbol used in Europe. If not, update your TTF files (free).
The developers using a US kbd can easily test their code with some non 中文版 chars just by using a few alt+0nn n Commands. Preferably, test some chars with a ANSI code > 127, just to see what ' s happen. A serious developer must do this.
If you don ' t know-to-type, try to enter correctly the word : attaché-case (attache[acute]-case)
Regards to all. Jean-michel Fauth, Switzerland.