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:
parent
f4a73c28a2
commit
684ac64742
|
@ -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[] = {
|
||||||
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// check keys
|
}
|
||||||
BYTE keys[256];
|
else {
|
||||||
if (GetKeyboardState(keys)) {
|
for (UInt32 i = 0; i < 256 / 32; ++i) {
|
||||||
for (unsigned int i = 0; i < sizeof(keys); ++i) {
|
for (UInt32 b = 1, j = 0; j < 32; b <<= 1, ++j) {
|
||||||
if ((keys[i] & 0x80) != 0) {
|
if ((s_mappedKeys[i] & b) != 0) {
|
||||||
|
if (GetAsyncKeyState(i * 32 + j) < 0) {
|
||||||
return true;
|
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,12 +1520,6 @@ CMSWindowsPrimaryScreen::updateKey(UINT vkCode, bool press)
|
||||||
}
|
}
|
||||||
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:
|
||||||
|
@ -1510,6 +1527,13 @@ CMSWindowsPrimaryScreen::updateKey(UINT vkCode, bool press)
|
||||||
m_keys[vkCode] &= ~0x80;
|
m_keys[vkCode] &= ~0x80;
|
||||||
m_keys[vkCode] ^= 0x01;
|
m_keys[vkCode] ^= 0x01;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
case VK_LWIN:
|
||||||
|
case VK_RWIN:
|
||||||
|
case VK_APPS:
|
||||||
|
m_keys[vkCode] &= ~0x80;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue