diff options
author | Oliver Wolff <oliver.wolff@digia.com> | 2014-06-05 09:43:04 +0200 |
---|---|---|
committer | Oliver Wolff <oliver.wolff@digia.com> | 2014-09-29 07:26:46 +0200 |
commit | dfe853bff90444edf92a993e391df853780c9e8d (patch) | |
tree | 4b1e490102100e9a5e98bccf6c3579f40b31e2ae /src | |
parent | 8456adf0eeb9df8dd5f0547d4ad5a81888295f03 (diff) |
Windows: Fix call of ToUnicode
ToUnicode sometimes gives wrong results if it is used with a
keyboard buffer containing the ctrl modifier. Special cases
containing alt and control might trigger the third assignment
of a key, but if no alt modifier is used for the key event,
we temporarily disable the control modifier in order to obtain
the character with ToUnicode.
Task-number: QTBUG-35734
Change-Id: Ifd88c640541b42fa65ee1dc9b55af3386714b0b8
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/platforms/windows/qwindowskeymapper.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/plugins/platforms/windows/qwindowskeymapper.cpp b/src/plugins/platforms/windows/qwindowskeymapper.cpp index ac9fe0878e..990dbaeba2 100644 --- a/src/plugins/platforms/windows/qwindowskeymapper.cpp +++ b/src/plugins/platforms/windows/qwindowskeymapper.cpp @@ -536,15 +536,16 @@ static inline int toKeyOrUnicode(int vk, int scancode, unsigned char *kbdBuffer, Q_ASSERT(vk > 0 && vk < 256); int code = 0; QChar unicodeBuffer[5]; - int res = ToUnicode(vk, scancode, kbdBuffer, reinterpret_cast<LPWSTR>(unicodeBuffer), 5, 0); - // When Ctrl modifier is used ToUnicode does not return correct values. In order to assign the - // right key the control modifier is removed for just that function if the previous call failed. - if (res == 0 && kbdBuffer[VK_CONTROL]) { - const unsigned char controlState = kbdBuffer[VK_CONTROL]; + // While key combinations containing alt and ctrl might trigger the third assignment of a key + // (for example "alt+ctrl+q" causes '@' on a German layout), ToUnicode often does not return the + // wanted character if only the ctrl modifier is used. Thus we unset this modifier temporarily + // if it is not used together with alt. + const unsigned char controlState = kbdBuffer[VK_MENU] ? 0 : kbdBuffer[VK_CONTROL]; + if (controlState) kbdBuffer[VK_CONTROL] = 0; - res = ToUnicode(vk, scancode, kbdBuffer, reinterpret_cast<LPWSTR>(unicodeBuffer), 5, 0); + int res = ToUnicode(vk, scancode, kbdBuffer, reinterpret_cast<LPWSTR>(unicodeBuffer), 5, 0); + if (controlState) kbdBuffer[VK_CONTROL] = controlState; - } if (res) code = unicodeBuffer[0].toUpper().unicode(); |