| 3093 | |
| 3094 | |
| 3095 | void UpdateKeybdState(KBDLLHOOKSTRUCT &aEvent, const vk_type aVK, const sc_type aSC, bool aKeyUp, bool aIsSuppressed) |
| 3096 | // Caller has ensured that vk has been translated from neutral to left/right if necessary. |
| 3097 | // Always use the parameter vk rather than event.vkCode because the caller or caller's caller |
| 3098 | // might have adjusted vk, namely to make it a left/right specific modifier key rather than a |
| 3099 | // neutral one. |
| 3100 | { |
| 3101 | // If this function was called from SuppressThisKey(), these comments apply: |
| 3102 | // Currently SuppressThisKey is only called with a modifier in the rare case |
| 3103 | // when sDisguiseNextLWinUp/RWinUp is in effect. But there may be other cases in the |
| 3104 | // future, so we need to make sure the physical state of the modifiers is updated |
| 3105 | // in our tracking system even though the key is being suppressed: |
| 3106 | modLR_type modLR; |
| 3107 | if (modLR = kvk[aVK].as_modifiersLR) // Update our tracking of LWIN/RWIN/RSHIFT etc. |
| 3108 | { |
| 3109 | // Caller has ensured that vk has been translated from neutral to left/right if necessary |
| 3110 | // (e.g. VK_CONTROL -> VK_LCONTROL). For this reason, always use the parameter vk rather |
| 3111 | // than the raw event.vkCode. |
| 3112 | // Below excludes KEY_IGNORE_ALL_EXCEPT_MODIFIER since that type of event shouldn't be ignored by |
| 3113 | // this function. UPDATE: KEY_PHYS_IGNORE is now considered to be something that shouldn't be |
| 3114 | // ignored in this case because if more than one instance has the hook installed, it is |
| 3115 | // possible for g_modifiersLR_logical_non_ignored to say that a key is down in one instance when |
| 3116 | // that instance's g_modifiersLR_logical doesn't say it's down, which is definitely wrong. So it |
| 3117 | // is now omitted below: |
| 3118 | bool is_not_ignored = (aEvent.dwExtraInfo != KEY_IGNORE); |
| 3119 | bool is_fake_shift = aEvent.scanCode == SC_FAKE_LSHIFT || aEvent.scanCode == SC_FAKE_RSHIFT; |
| 3120 | bool is_fake_ctrl = aEvent.scanCode == SC_FAKE_LCTRL; // AltGr. |
| 3121 | // For backward-compatibility, fake LCtrl is marked as physical. |
| 3122 | bool event_is_physical = !is_fake_shift && KeybdEventIsPhysical(aEvent.flags, aVK, aKeyUp); |
| 3123 | |
| 3124 | if (aKeyUp) |
| 3125 | { |
| 3126 | // Keep track of system-generated Shift-up events (as part of a workaround for |
| 3127 | // Shift becoming stuck due to interaction between Send and the system handling |
| 3128 | // of shift-numpad combinations). Find "fake shift" for more details. |
| 3129 | if (is_fake_shift) |
| 3130 | g_modifiersLR_numpad_mask |= modLR; |
| 3131 | if (!aIsSuppressed) |
| 3132 | { |
| 3133 | g_modifiersLR_logical &= ~modLR; |
| 3134 | // Even if is_not_ignored == true, this is updated unconditionally on key-up events |
| 3135 | // to ensure that g_modifiersLR_logical_non_ignored never says a key is down when |
| 3136 | // g_modifiersLR_logical says its up, which might otherwise happen in cases such |
| 3137 | // as alt-tab. See this comment further below, where the operative word is "relied": |
| 3138 | // "key pushed ALT down, or relied upon it already being down, so go up". UPDATE: |
| 3139 | // The above is no longer a concern because KeyEvent() now defaults to the mode |
| 3140 | // which causes our var "is_not_ignored" to be true here. Only the Send command |
| 3141 | // overrides this default, and it takes responsibility for ensuring that the older |
| 3142 | // comment above never happens by forcing any down-modifiers to be up if they're |
| 3143 | // not logically down as reflected in g_modifiersLR_logical. There's more |
| 3144 | // explanation for g_modifiersLR_logical_non_ignored in keyboard_mouse.h: |
| 3145 | if (is_not_ignored) |
| 3146 | g_modifiersLR_logical_non_ignored &= ~modLR; |
| 3147 | } |
| 3148 | if (event_is_physical) // Note that ignored events can be physical via KEYEVENT_PHYS() |
| 3149 | { |
| 3150 | g_modifiersLR_physical &= ~modLR; |
| 3151 | g_PhysicalKeyState[aVK] = 0; |
| 3152 | if (!is_fake_ctrl) |
no test coverage detected