I've found a wierd bug in keyboard handling. The problem is that wine
doesn't seem to correctly translate key board messages. The program
receives WM_KEYDOWN VK_NUMPAD2 and WM_KEYUP VK_DOWN(really bad).
I've traced the bug to dlls/x11drv/keyboard.c. Apparently
EVENT_event_to_vkey correctly converts KeyPress message, but not
KeyRelease messages. If you look at the source code there is a hack of
sorts for numpad keys. EVENT_event_to_vkey calls something from X to get
a keysym, and does some special handling for numpad 0-9 and dot.
Apparently for the KeyRelease event that doesn't work, keysym comes back
as 0, causing EVENT_event_to_vkey to malfunction.
This bug doesn't always happen (but it does most of the time). I'm
scared this might be a bug in my X, but I hope it's not. BTW, isn't
there a better way to handle numpad stuff?
Here is the relevant portion of the wine log:
trace:key:X11DRV_KeyEvent type 2, window 3600001, state 0x0010, keycode
0x0058
trace:key:X11DRV_KeyEvent state = 10 nbyte = 1, status 0x4
trace:key:X11DRV_KeyEvent KeyPress : keysym=FFB2 (KP_2), # of chars=1 /
0x32 / '2'
trace:key:X11DRV_KeyEvent keycode 0x58 converted to vkey 0x62
trace:key:X11DRV_KeyEvent bScan = 0x50.
trace:key:queue_kbd_event wParam=0062, lParam=40500001,
InputKeyState=81
trace:msg:MSG_peek_message got type 7 msg 100 (WM_KEYDOWN) hwnd 0x10022
wp 62 lp 40500001
trace:msg:MSG_peek_message got type 7 msg 100 (WM_KEYDOWN) hwnd 0x10022
wp 62 lp 40500001
trace:key:TranslateMessage (WM_KEYDOWN, 0062, 40500001)
trace:key:TranslateMessage Translating key VK_NUMPAD2 (0062), scancode
50
trace:msg:GetKeyboardState (0x778da29c)
trace:key:X11DRV_ToUnicodeEx (0062, 4050) : faked state = 0x0010
trace:key:X11DRV_ToUnicodeEx type 2, window 3600001, state 0x0010,
keycode 0x0058
trace:key:X11DRV_ToUnicodeEx Translating char 0x32 to unicode
trace:key:X11DRV_ToUnicodeEx ToUnicode about to return 1 with char 32
trace:key:TranslateMessage 1 ->
PostMessageW(0x10022,WM_CHAR,0032,40500001)
trace:msg:PostMessageW hwnd 0x10022 msg 102 (WM_CHAR) wp 32 lp 40500001
trace:msg:GetKeyState key (0x14) -> 0
trace:msg:MSG_peek_message got type 6 msg 102 (WM_CHAR) hwnd 0x10022 wp
32 lp 40500001
trace:msg:MSG_peek_message got type 6 msg 102 (WM_CHAR) hwnd 0x10022 wp
32 lp 40500001
trace:key:TranslateMessage (WM_CHAR, 0032, 40500001)
trace:key:X11DRV_KeyEvent type 3, window 3600001, state 0x0010, keycode
0x0058
trace:key:X11DRV_KeyEvent state = 10 nbyte = 0, status 0x1
trace:key:X11DRV_KeyEvent KeyRelease : keysym=0 (No Name), # of
chars=0 / 0x00 / ''
trace:key:EVENT_event_to_vkey e->keycode = 58
trace:key:X11DRV_KeyEvent keycode 0x58 converted to vkey 0x28
trace:key:X11DRV_KeyEvent bScan = 0x50.
trace:key:queue_kbd_event wParam=0028, lParam=c0500001, InputKeyState=0
trace:msg:MSG_peek_message got type 7 msg 101 (WM_KEYUP) hwnd 0x10022 wp
28 lp c0500001
trace:msg:MSG_peek_message got type 7 msg 101 (WM_KEYUP) hwnd 0x10022 wp
28 lp c0500001
trace:key:TranslateMessage (WM_KEYUP, 0028, C0500001)