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.
This commit is contained in:
crs 2002-07-01 13:00:12 +00:00
parent f4a73c28a2
commit 684ac64742
1 changed files with 49 additions and 25 deletions

View File

@ -347,22 +347,44 @@ CMSWindowsPrimaryScreen::getToggleMask() const
bool bool
CMSWindowsPrimaryScreen::isLockedToScreen() const CMSWindowsPrimaryScreen::isLockedToScreen() const
{ {
// check buttons // virtual key table. the table defines the virtual keys that are
if (GetAsyncKeyState(VK_LBUTTON) < 0 || // mapped to something (including mouse buttons, OEM and kanji keys
GetAsyncKeyState(VK_MBUTTON) < 0 || // but not unassigned or undefined keys).
GetAsyncKeyState(VK_RBUTTON) < 0) { static const UInt32 s_mappedKeys[] = {
return true; 0xfbff331e,
} 0x03ffffff,
0x3ffffffe,
0xffffffff,
0x000300ff,
0xfc000000,
0xf8000001,
0x7ffffe5f
};
// check keys // check each key. note that we cannot use GetKeyboardState() here
BYTE keys[256]; // since it reports the state of keys according to key messages
if (GetKeyboardState(keys)) { // that have been pulled off the queue. in general, we won't get
for (unsigned int i = 0; i < sizeof(keys); ++i) { // these key messages because they're not for our window. if any
if ((keys[i] & 0x80) != 0) { // 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; 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 // not locked
return false; return false;
@ -1454,18 +1476,19 @@ CMSWindowsPrimaryScreen::updateKey(UINT vkCode, bool press)
m_keys[VK_MENU] |= 0x80; m_keys[VK_MENU] |= 0x80;
break; break;
case VK_LWIN:
case VK_RWIN:
case VK_APPS:
m_keys[vkCode] |= 0x80;
break;
case VK_CAPITAL: case VK_CAPITAL:
case VK_NUMLOCK: case VK_NUMLOCK:
case VK_SCROLL: case VK_SCROLL:
// toggle keys // toggle keys
m_keys[vkCode] |= 0x80; m_keys[vkCode] |= 0x80;
break; break;
default:
case VK_LWIN:
case VK_RWIN:
case VK_APPS:
m_keys[vkCode] |= 0x80;
break;
} }
} }
else { else {
@ -1497,19 +1520,20 @@ CMSWindowsPrimaryScreen::updateKey(UINT vkCode, bool press)
} }
break; 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_LWIN:
case VK_RWIN: case VK_RWIN:
case VK_APPS: case VK_APPS:
m_keys[vkCode] &= ~0x80; m_keys[vkCode] &= ~0x80;
break; break;
case VK_CAPITAL:
case VK_NUMLOCK:
case VK_SCROLL:
// toggle keys
m_keys[vkCode] &= ~0x80;
m_keys[vkCode] ^= 0x01;
break;
} }
} }
} }