diff options
author | Oliver Wolff <oliver.wolff@digia.com> | 2012-11-14 12:06:15 (GMT) |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-11-14 12:54:32 (GMT) |
commit | 98b49f88fa1dfe593bf8e4291bd12419d47c26aa (patch) | |
tree | 89ba635aa4099a0b306daf1f7ac4cf635e2d89d5 | |
parent | 2b7ec50666d9e9b2cd8c0c74e8a3c889b77cfd1e (diff) | |
download | Qt-98b49f88fa1dfe593bf8e4291bd12419d47c26aa.zip Qt-98b49f88fa1dfe593bf8e4291bd12419d47c26aa.tar.gz Qt-98b49f88fa1dfe593bf8e4291bd12419d47c26aa.tar.bz2 |
Windows: Fixed handling of key events containing ctrl modifier
QKeyEvent::key() returned the wrong value if the ctrl modifier was used
in that key event. That was due to the fact that ToUnicode might not
return the correct code for these events/keyboard states. While it works
for alt+shift+= (us layout) and gives '+' as unicode value it just
claims that it cannot translate the given state for ctrl+shift+=. So if
the control modifier is used and ToUnicode return 0 toKeyOrUnicode
should try again without the control modifier.
Task-number: QTBUG-10781
Change-Id: I771f7ed18bcce60d1c7c3f6157d169d4e80ddd60
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
-rw-r--r-- | src/gui/kernel/qkeymapper_win.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/gui/kernel/qkeymapper_win.cpp b/src/gui/kernel/qkeymapper_win.cpp index dfa7c96..a776516 100644 --- a/src/gui/kernel/qkeymapper_win.cpp +++ b/src/gui/kernel/qkeymapper_win.cpp @@ -483,6 +483,14 @@ static inline int toKeyOrUnicode(int vk, int scancode, unsigned char *kbdBuffer, 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]; + kbdBuffer[VK_CONTROL] = 0; + res = ToUnicode(vk, scancode, kbdBuffer, reinterpret_cast<LPWSTR>(unicodeBuffer), 5, 0); + kbdBuffer[VK_CONTROL] = controlState; + } if (res) code = unicodeBuffer[0].toUpper().unicode(); |