| 3198 | |
| 3199 | |
| 3200 | bool KeybdEventIsPhysical(DWORD aEventFlags, const vk_type aVK, bool aKeyUp) |
| 3201 | // Always use the parameter vk rather than event.vkCode because the caller or caller's caller |
| 3202 | // might have adjusted vk, namely to make it a left/right specific modifier key rather than a |
| 3203 | // neutral one. |
| 3204 | { |
| 3205 | // MSDN: "The keyboard input can come from the local keyboard driver or from calls to the keybd_event |
| 3206 | // function. If the input comes from a call to keybd_event, the input was "injected"". |
| 3207 | // My: This also applies to mouse events, so use it for them too: |
| 3208 | if (aEventFlags & LLKHF_INJECTED) |
| 3209 | return false; |
| 3210 | // So now we know it's a physical event. But certain SHIFT key-down events are driver-generated. |
| 3211 | // We want to be able to tell the difference because the Send command and other aspects |
| 3212 | // of keyboard functionality need us to be accurate about which keys the user is physically |
| 3213 | // holding down at any given time: |
| 3214 | if ( (aVK == VK_LSHIFT || aVK == VK_RSHIFT) && !aKeyUp ) |
| 3215 | { |
| 3216 | // If the corresponding mask bit is set, the key was temporarily "released" by the system |
| 3217 | // as part of translating a shift-numpad combination to its unshifted counterpart, and this |
| 3218 | // event is the fake key-down which follows the release of the numpad key. The system uses |
| 3219 | // standard scancodes for this specific case, not SC_FAKE_LSHIFT or SC_FAKE_RSHIFT. |
| 3220 | if (g_modifiersLR_numpad_mask & (aVK == VK_LSHIFT ? MOD_LSHIFT : MOD_RSHIFT)) |
| 3221 | return false; |
| 3222 | } |
| 3223 | |
| 3224 | // Otherwise, it's physical. |
| 3225 | // v1.0.42.04: |
| 3226 | // The time member of the incoming event struct has been observed to be wrongly zero sometimes, perhaps only |
| 3227 | // for AltGr keyboard layouts that generate LControl events when RAlt is pressed (but in such cases, I think |
| 3228 | // it's only sometimes zero, not always). It might also occur during simulation of Alt+Numpad keystrokes |
| 3229 | // to support {Asc NNNN}. In addition, SendInput() is documented to have the ability to set its own timestamps; |
| 3230 | // if it's callers put in a bad timestamp, it will probably arrive here that way too. Thus, use GetTickCount(). |
| 3231 | // More importantly, when a script or other application simulates an AltGr keystroke (either down or up), |
| 3232 | // the LControl event received here is marked as physical by the OS or keyboard driver. This is undesirable |
| 3233 | // primarily because it makes g_TimeLastInputPhysical inaccurate, but also because falsely marked physical |
| 3234 | // events can impact the script's calls to GetKeyState("LControl", "P"), etc. |
| 3235 | g_TimeLastInputPhysical = g_TimeLastInputKeyboard = GetTickCount(); |
| 3236 | return true; |
| 3237 | } |
| 3238 | |
| 3239 | |
| 3240 | ///////////////////////////////////////////////////////////////////////////////////////// |
no outgoing calls
no test coverage detected