From 9b4cec76f1d7792d4bf64fa069ea6b64bc42da0d Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Mon, 5 Nov 2012 15:05:32 +0000 Subject: [PATCH] hw/xwin: Consider left and right modifier keys independently on gaining focus Handle left and right ctrl and shift keys independently Assume that all modifiers are cleared when all keys are released on focus lost, as internalKeyState doesn't record which modifier key was pressed. Signed-off-by: Jon TURNEY Reviewed-by: Colin Harrison --- hw/xwin/winkeybd.c | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/hw/xwin/winkeybd.c b/hw/xwin/winkeybd.c index e412f2355..27432e13f 100644 --- a/hw/xwin/winkeybd.c +++ b/hw/xwin/winkeybd.c @@ -264,25 +264,38 @@ winRestoreModeKeyStates(void) /* Check if modifier keys are pressed, and if so, fake a press */ { - BOOL ctrl = (GetAsyncKeyState(VK_CONTROL) < 0); - BOOL shift = (GetAsyncKeyState(VK_SHIFT) < 0); + + BOOL lctrl = (GetAsyncKeyState(VK_LCONTROL) < 0); + BOOL rctrl = (GetAsyncKeyState(VK_RCONTROL) < 0); + BOOL lshift = (GetAsyncKeyState(VK_LSHIFT) < 0); + BOOL rshift = (GetAsyncKeyState(VK_RSHIFT) < 0); BOOL alt = (GetAsyncKeyState(VK_LMENU) < 0); BOOL altgr = (GetAsyncKeyState(VK_RMENU) < 0); - if (ctrl && altgr) - ctrl = FALSE; + /* + If AltGr and CtrlL appear to be pressed, assume the + CtrL is a fake one + */ + if (lctrl && altgr) + lctrl = FALSE; - if (LOGICAL_XOR(internalKeyStates & ControlMask, ctrl)) - winSendKeyEvent(KEY_LCtrl, ctrl); + if (lctrl) + winSendKeyEvent(KEY_LCtrl, TRUE); - if (LOGICAL_XOR(internalKeyStates & ShiftMask, shift)) - winSendKeyEvent(KEY_ShiftL, shift); + if (rctrl) + winSendKeyEvent(KEY_RCtrl, TRUE); - if (LOGICAL_XOR(internalKeyStates & Mod1Mask, alt)) - winSendKeyEvent(KEY_Alt, alt); + if (lshift) + winSendKeyEvent(KEY_ShiftL, TRUE); - if (LOGICAL_XOR(internalKeyStates & Mod5Mask, altgr)) - winSendKeyEvent(KEY_AltLang, altgr); + if (rshift) + winSendKeyEvent(KEY_ShiftL, TRUE); + + if (alt) + winSendKeyEvent(KEY_Alt, TRUE); + + if (altgr) + winSendKeyEvent(KEY_AltLang, TRUE); } /* @@ -313,6 +326,12 @@ winRestoreModeKeyStates(void) winSendKeyEvent(KEY_HKTG, TRUE); winSendKeyEvent(KEY_HKTG, FALSE); } + + /* + For strict correctness, we should also press any non-modifier keys + which are already down when we gain focus, but nobody has complained + yet :-) + */ } /*