diff options
author | fvogel <fvogelnew1@free.fr> | 2016-08-12 16:51:23 (GMT) |
---|---|---|
committer | fvogel <fvogelnew1@free.fr> | 2016-08-12 16:51:23 (GMT) |
commit | a498656bff1b7ff55c949c4311b1bfb4c307c02e (patch) | |
tree | 6a53ad9e903d3a3aac5cbd117e40c7d5982a5ba8 | |
parent | 4fa07b0a11a1de74bd15b1ae9dcec8be210fcd34 (diff) | |
download | tk-bug_2945130fff_shift.zip tk-bug_2945130fff_shift.tar.gz tk-bug_2945130fff_shift.tar.bz2 |
Solution for differentiating left and right shift keys.bug_2945130fff_shift
-rw-r--r-- | win/tkWinKey.c | 17 | ||||
-rw-r--r-- | win/tkWinX.c | 15 |
2 files changed, 23 insertions, 9 deletions
diff --git a/win/tkWinKey.c b/win/tkWinKey.c index 10cc7b8..d4e7223 100644 --- a/win/tkWinKey.c +++ b/win/tkWinKey.c @@ -339,14 +339,13 @@ KeycodeToKeysym( * and Alt (aka Menu) keys are such extended keys (which their left * counterparts are not). * Regarding the shift case, Windows does not set the Extended flag for - * the neither the left nor the right shift key. As a consequence another - * way to distinguish between the two keys is to query the state of one - * of the two to determine which was actually pressed. So if the keycode - * indicates Shift, do this extra test. If the right-side key was - * pressed, return the appropriate keycode. Otherwise, we fall through - * and rely on the keymap table to hold the correct keysym value. - * Note: this little trick only works for KeyPress, not for KeyRelease, - * for reasons stated in bug [2945130] + * neither the left nor the right shift key. This is therefore manually + * enforced at KeyPress/KeyRelease event generation time (in tkWinX.c). + * This is a bit of a hack but there is no other way that would work + * for both KeyPress and KeyRelease events. + * If the right-side key was pressed, return the appropriate keycode. + * Otherwise, we fall through and rely on the keymap table to hold the + * correct keysym value. */ case VK_CONTROL: @@ -355,7 +354,7 @@ KeycodeToKeysym( } break; case VK_SHIFT: - if (GetKeyState(VK_RSHIFT) & 0x80) { + if (state & EXTENDED_MASK) { return XK_Shift_R; } break; diff --git a/win/tkWinX.c b/win/tkWinX.c index 567b281..2f81ece 100644 --- a/win/tkWinX.c +++ b/win/tkWinX.c @@ -1323,6 +1323,21 @@ GetState( if (HIWORD(lParam) & KF_EXTENDED) { state |= EXTENDED_MASK; } + + /* + * Windows does not set the Extended flag for neither the left nor the right + * shift key. Since we need to distinguish later at event handling time + * which one was pressed, we force the Extended flag manually here so that + * KeycodeToKeysym() in tkWinKey.c can return the correct left or right + * keysym. Detection is based on the scan code contained in lParam. + * This is a bit of a hack but there is no other way that would work + * for both KeyPress and KeyRelease events. + */ + + if ((wParam == VK_SHIFT) && + ((HIWORD(lParam) & 0xFF) != MapVirtualKey(VK_LSHIFT, 0))) { + state |= EXTENDED_MASK; + } } return state; } |