From 684ac64742c2d28612f5e3be65ae2368ed3d823e Mon Sep 17 00:00:00 2001 From: crs Date: Mon, 1 Jul 2002 13:00:12 +0000 Subject: [PATCH] fixed locking to screen on win32. was using GetKeyboardState() to query keys but that doesn't give us up-to-date information. now using GetAsyncKeyState() if on primary and m_keys if on secondary. --- server/CMSWindowsPrimaryScreen.cpp | 74 ++++++++++++++++++++---------- 1 file changed, 49 insertions(+), 25 deletions(-) diff --git a/server/CMSWindowsPrimaryScreen.cpp b/server/CMSWindowsPrimaryScreen.cpp index 1631ab7f..55b43441 100644 --- a/server/CMSWindowsPrimaryScreen.cpp +++ b/server/CMSWindowsPrimaryScreen.cpp @@ -347,22 +347,44 @@ CMSWindowsPrimaryScreen::getToggleMask() const bool CMSWindowsPrimaryScreen::isLockedToScreen() const { - // check buttons - if (GetAsyncKeyState(VK_LBUTTON) < 0 || - GetAsyncKeyState(VK_MBUTTON) < 0 || - GetAsyncKeyState(VK_RBUTTON) < 0) { - return true; - } + // virtual key table. the table defines the virtual keys that are + // mapped to something (including mouse buttons, OEM and kanji keys + // but not unassigned or undefined keys). + static const UInt32 s_mappedKeys[] = { + 0xfbff331e, + 0x03ffffff, + 0x3ffffffe, + 0xffffffff, + 0x000300ff, + 0xfc000000, + 0xf8000001, + 0x7ffffe5f + }; - // check keys - BYTE keys[256]; - if (GetKeyboardState(keys)) { - for (unsigned int i = 0; i < sizeof(keys); ++i) { - if ((keys[i] & 0x80) != 0) { + // check each key. note that we cannot use GetKeyboardState() here + // since it reports the state of keys according to key messages + // that have been pulled off the queue. in general, we won't get + // these key messages because they're not for our window. if any + // key (or mouse button) is down then we're locked to the screen. + if (m_active) { + // use shadow keyboard state in m_keys + for (UInt32 i = 0; i < 256; ++i) { + if ((m_keys[i] & 0x80) != 0) { return true; } } } + else { + for (UInt32 i = 0; i < 256 / 32; ++i) { + for (UInt32 b = 1, j = 0; j < 32; b <<= 1, ++j) { + if ((s_mappedKeys[i] & b) != 0) { + if (GetAsyncKeyState(i * 32 + j) < 0) { + return true; + } + } + } + } + } // not locked return false; @@ -1454,18 +1476,19 @@ CMSWindowsPrimaryScreen::updateKey(UINT vkCode, bool press) m_keys[VK_MENU] |= 0x80; break; - case VK_LWIN: - case VK_RWIN: - case VK_APPS: - m_keys[vkCode] |= 0x80; - break; - case VK_CAPITAL: case VK_NUMLOCK: case VK_SCROLL: // toggle keys m_keys[vkCode] |= 0x80; break; + + default: + case VK_LWIN: + case VK_RWIN: + case VK_APPS: + m_keys[vkCode] |= 0x80; + break; } } else { @@ -1497,19 +1520,20 @@ CMSWindowsPrimaryScreen::updateKey(UINT vkCode, bool press) } break; + case VK_CAPITAL: + case VK_NUMLOCK: + case VK_SCROLL: + // toggle keys + m_keys[vkCode] &= ~0x80; + m_keys[vkCode] ^= 0x01; + break; + + default: case VK_LWIN: case VK_RWIN: case VK_APPS: m_keys[vkCode] &= ~0x80; break; - - case VK_CAPITAL: - case VK_NUMLOCK: - case VK_SCROLL: - // toggle keys - m_keys[vkCode] &= ~0x80; - m_keys[vkCode] ^= 0x01; - break; } } }