[Python-bugs-list] PythonWin crash on dead keys (PR#372)

gottfried.ganssauge@dynix.de gottfried.ganssauge@dynix.de
Tue, 27 Jun 2000 09:08:23 -0400 (EDT)


Full_Name: Gottfried Ganßauge
Version: 1.5.2
OS: Windows 2000
Submission from: joshua2go.dynix.de (195.21.130.43)


I'm using PyWin32 build 132, but the problem occurs with build 129 as well.

Every time I hit one of the dead keys on my keyboard (`, ^) PythonWin crashes.
I traced the error back to the routine ui_translate_vk() in win32uimodule.cpp.
The call to ToAsciiEx() with a dead key's scan code returns -1 and in the
following call to PyString_FromStringAndSize() this eventually leads to the
crash.
In my opininion the reason for that lies before the call to this routine.
pywin hooks WM_KEYDOWN in several places and doesn't check for dead keys but
tries to translate the scan code to an ASCII character.
With dead keys this obviously must fail.
Windows itself already does the correct translation as described in the
Platform SDK article about Dead-Character Messages:
<Quote on>
Some non-English keyboards contain character keys that are not expected to
produce characters by themselves. Instead, they are used to add a diacritic to
the character produced by the subsequent keystroke. These keys are called dead
keys. The circumflex key on a German keyboard is an example of a dead key. To
enter the character consisting of an "o" with a circumflex, a German user would
type the circumflex key followed by the "o" key. The window with the keyboard
focus would receive the following sequence of messages: 

WM_KEYDOWN 
WM_DEADCHAR 
WM_KEYUP 
WM_KEYDOWN 
WM_CHAR 
WM_KEYUP 
<Quote off>

Consequently pywin should ignore WM_KEYDOWN messages completely if they are
produced by a dead key.
I tried to implement that using the current win32api implementation, but
unfortunately the necessary API-Function to find out if a key is a dead key are
not provided in the current implementation; namely the MapVirtualKey(Ex)
function.

Cheers, and keep up the good work

Gottfried