From 3ab36b2f4665ac51a8a6774fe7151c5cff9bf303 Mon Sep 17 00:00:00 2001 From: marha Date: Tue, 15 Mar 2011 08:56:37 +0000 Subject: Solved problem of GetKeyState not always returning the correct state in WM_SETFOCUS --- xorg-server/hw/xwin/winkeybd.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'xorg-server') diff --git a/xorg-server/hw/xwin/winkeybd.c b/xorg-server/hw/xwin/winkeybd.c index 4711a0d96..e53d84b3f 100644 --- a/xorg-server/hw/xwin/winkeybd.c +++ b/xorg-server/hw/xwin/winkeybd.c @@ -276,6 +276,21 @@ winRestoreModeKeyStates (void) internalKeyStates = XkbStateFieldFromRec(&inputInfo.keyboard->key->xkbInfo->state); winDebug("winRestoreModeKeyStates: state %d\n", internalKeyStates); + { + /* Make sure the message queue is empty, otherwise the GetKeyState will not always + return the correct state of the numlock key, capslock key, ... + This is mainly because this function is called from the WM_SETFOCUS handler. + From MSDN GetKeyState: The key status returned from this function changes as a thread + reads key messages from its message queue.*/ + MSG msg; + + /* Process all messages on our queue */ + while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) + { + DispatchMessage (&msg); + } + } + /* * NOTE: The C XOR operator, ^, will not work here because it is * a bitwise operator, not a logical operator. C does not -- cgit v1.2.3