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
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
This commit is contained in:
Oliver Wolff 2013-11-19 12:47:03 +01:00 committed by The Qt Project
parent a0e32cbf74
commit d4c548ce5c

View File

@ -86,6 +86,10 @@ QWindowsKeyMapper::~QWindowsKeyMapper()
#define VK_OEM_3 0xC0
#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) {}
@ -567,7 +571,7 @@ void QWindowsKeyMapper::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);
}
@ -754,7 +758,7 @@ bool QWindowsKeyMapper::translateKeyEventInternal(QWindow *window, const MSG &ms
{
const int msgType = msg.message;
const quint32 scancode = (msg.lParam >> 16) & 0xff;
const quint32 scancode = (msg.lParam >> 16) & scancodeBitmask;
const quint32 vk_key = msg.wParam;
quint32 nModifiers = 0;