| 17308 | |
| 17309 | |
| 17310 | bool ScriptGetKeyState(vk_type aVK, KeyStateTypes aKeyStateType) |
| 17311 | // Returns true if "down", false if "up". |
| 17312 | { |
| 17313 | if (!aVK) // Assume "up" if indeterminate. |
| 17314 | return false; |
| 17315 | |
| 17316 | switch (aKeyStateType) |
| 17317 | { |
| 17318 | case KEYSTATE_TOGGLE: // Whether a toggleable key such as CapsLock is currently turned on. |
| 17319 | return IsKeyToggledOn(aVK); // This also works for non-"lock" keys, but in that case the toggle state can be out of sync with other processes/threads. |
| 17320 | case KEYSTATE_PHYSICAL: // Physical state of key. |
| 17321 | if (IsMouseVK(aVK)) // mouse button |
| 17322 | { |
| 17323 | if (g_MouseHook) // mouse hook is installed, so use it's tracking of physical state. |
| 17324 | return g_PhysicalKeyState[aVK] & STATE_DOWN; |
| 17325 | else |
| 17326 | return IsKeyDownAsync(aVK); |
| 17327 | } |
| 17328 | else // keyboard |
| 17329 | { |
| 17330 | if (g_KeybdHook) |
| 17331 | { |
| 17332 | // Since the hook is installed, use its value rather than that from |
| 17333 | // GetAsyncKeyState(), which doesn't seem to return the physical state. |
| 17334 | // But first, correct the hook modifier state if it needs it. See comments |
| 17335 | // in GetModifierLRState() for why this is needed: |
| 17336 | if (KeyToModifiersLR(aVK)) // It's a modifier. |
| 17337 | GetModifierLRState(true); // Correct hook's physical state if needed. |
| 17338 | return g_PhysicalKeyState[aVK] & STATE_DOWN; |
| 17339 | } |
| 17340 | else |
| 17341 | return IsKeyDownAsync(aVK); |
| 17342 | } |
| 17343 | } // switch() |
| 17344 | |
| 17345 | // Otherwise, use the default state-type: KEYSTATE_LOGICAL |
| 17346 | // On XP/2K at least, a key can be physically down even if it isn't logically down, |
| 17347 | // which is why the below specifically calls IsKeyDown() rather than some more |
| 17348 | // comprehensive method such as consulting the physical key state as tracked by the hook: |
| 17349 | // v1.0.42.01: For backward compatibility, the following hasn't been changed to IsKeyDownAsync(). |
| 17350 | // One example is the journal playback hook: when a window owned by the script receives |
| 17351 | // such a keystroke, only GetKeyState() can detect the changed state of the key, not GetAsyncKeyState(). |
| 17352 | // A new mode can be added to KeyWait & GetKeyState if Async is ever explicitly needed. |
| 17353 | return IsKeyDown(aVK); |
| 17354 | } |
| 17355 | |
| 17356 | |
| 17357 |
no test coverage detected