summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qkeymapper_win.cpp
diff options
context:
space:
mode:
authorOliver Wolff <oliver.wolff@digia.com>2013-11-19 11:47:03 (GMT)
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-11-27 07:04:46 (GMT)
commit0af360cff29fbc1182d3553255091de2cc673194 (patch)
tree6a1568294c8d3ed6767b3778c33e7325bb35ab08 /src/gui/kernel/qkeymapper_win.cpp
parent157da36977213237939df14608753bb3ec280f0b (diff)
downloadQt-0af360cff29fbc1182d3553255091de2cc673194.zip
Qt-0af360cff29fbc1182d3553255091de2cc673194.tar.gz
Qt-0af360cff29fbc1182d3553255091de2cc673194.tar.bz2
Fixed assert in Windows key handling
Certain key sequences (like press alt, press left, release left, release alt) can cause an assert in qwindowskeymapper. This behavior was introduced in change I4f7709a90906b03f4504deea1ff5c361e9f94b3f (Fix virtual key mapping on MS Windows). The place that seems to cause the new behavior is changing the bitmask for obtaining the event's scancode. With the changed bitmask releasing the alt key in the given key sequence causes the WM_KEYUP event to trigger a WM_CHAR event which should not happen there. To be honest I don't know how having the extended bit inside the scancode fixes the behavior but it seems to do and I could not find another place which might cause the breakage. Task-number: QTBUG-35005 Change-Id: Ia18c2681ea311196441a5cd15017e220ac095674 (cherry picked from commit d4c548ce5c0bd8a70c82ed082bc69fd41e9c47ed) Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Juan Luis Boya GarcĂ­a <ntrrgc@gmail.com>
Diffstat (limited to 'src/gui/kernel/qkeymapper_win.cpp')
-rw-r--r--src/gui/kernel/qkeymapper_win.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/gui/kernel/qkeymapper_win.cpp b/src/gui/kernel/qkeymapper_win.cpp
index 429e40d..159c47d 100644
--- a/src/gui/kernel/qkeymapper_win.cpp
+++ b/src/gui/kernel/qkeymapper_win.cpp
@@ -86,6 +86,12 @@ bool GetKeyboardState(unsigned char* kbuffer)
return true;
}
#endif
+
+// We not only need the scancode itself but also the extended bit of key messages. Thus we need
+// the additional bit when masking the scancode.
+enum { scancodeBitmask = 0x1ff };
+
+
// Key recorder ------------------------------------------------------------------------[ start ] --
struct KeyRecord {
KeyRecord(int c, int a, int s, const QString &t) : code(c), ascii(a), state(s), text(t) {}
@@ -662,7 +668,7 @@ void QKeyMapperPrivate::updateKeyMap(const MSG &msg)
{
unsigned char kbdBuffer[256]; // Will hold the complete keyboard state
GetKeyboardState(kbdBuffer);
- const quint32 scancode = (msg.lParam >> 16) & 0xff;
+ const quint32 scancode = (msg.lParam >> 16) & scancodeBitmask;
updatePossibleKeyCodes(kbdBuffer, scancode, msg.wParam);
}
@@ -800,7 +806,7 @@ bool QKeyMapperPrivate::translateKeyEvent(QWidget *widget, const MSG &msg, bool
// Add this key to the keymap if it is not present yet.
updateKeyMap(msg);
- const quint32 scancode = (msg.lParam >> 16) & 0xff;
+ const quint32 scancode = (msg.lParam >> 16) & scancodeBitmask;
const quint32 vk_key = msg.wParam;
quint32 nModifiers = 0;