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
CMSWindowsPrimaryScreen::isLockedToScreen() const
{
// check buttons
if (GetAsyncKeyState(VK_LBUTTON) < 0 ||
GetAsyncKeyState(VK_MBUTTON) < 0 ||
GetAsyncKeyState(VK_RBUTTON) < 0) {
// 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 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;
}
// check keys
BYTE keys[256];
if (GetKeyboardState(keys)) {
for (unsigned int i = 0; i < sizeof(keys); ++i) {
if ((keys[i] & 0x80) != 0) {
}
}
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,12 +1520,6 @@ CMSWindowsPrimaryScreen::updateKey(UINT vkCode, bool press)
}
break;
case VK_LWIN:
case VK_RWIN:
case VK_APPS:
m_keys[vkCode] &= ~0x80;
break;
case VK_CAPITAL:
case VK_NUMLOCK:
case VK_SCROLL:
@ -1510,6 +1527,13 @@ CMSWindowsPrimaryScreen::updateKey(UINT vkCode, bool press)
m_keys[vkCode] &= ~0x80;
m_keys[vkCode] ^= 0x01;
break;
default:
case VK_LWIN:
case VK_RWIN:
case VK_APPS:
m_keys[vkCode] &= ~0x80;
break;
}
}
}