MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / AllowIt

Function AllowIt

source/hook.cpp:2022–2271  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2020
2021
2022LRESULT AllowIt(const HHOOK aHook, int aCode, WPARAM wParam, LPARAM lParam, const vk_type aVK, const sc_type aSC
2023 , bool aKeyUp, ULONG_PTR aExtraInfo, KeyHistoryItem *pKeyHistoryCurr, WPARAM aHotkeyIDToPost)
2024// Always use the parameter vk rather than event.vkCode because the caller or caller's caller
2025// might have adjusted vk, namely to make it a left/right specific modifier key rather than a
2026// neutral one.
2027{
2028 WPARAM hs_wparam_to_post = HOTSTRING_INDEX_INVALID; // Set default.
2029 LPARAM hs_lparam_to_post; // Not initialized because the above is the sole indicator of whether its contents should even be examined.
2030
2031 // Prevent toggleable keys from being toggled (if the user wanted that) by suppressing it.
2032 // Seems best to suppress key-up events as well as key-down, since a key-up by itself,
2033 // if seen by the system, doesn't make much sense and might have unwanted side-effects
2034 // in rare cases (e.g. if the foreground app takes note of these types of key events).
2035 // Don't do this for ignored keys because that could cause an endless loop of
2036 // numlock events due to the keybd events that SuppressThisKey sends.
2037 // It's a little more readable and comfortable not to rely on short-circuit
2038 // booleans and instead do these conditions as separate IF statements.
2039 if (aHook == g_MouseHook)
2040 {
2041 // Since a mouse button that is physically down is not necessarily logically down -- such as
2042 // when the mouse button is a suppressed hotkey -- only update the logical state (which is the
2043 // state the OS believes the key to be in) when this event is non-supressed (i.e. allowed to
2044 // go to the system):
2045#ifdef FUTURE_USE_MOUSE_BUTTONS_LOGICAL
2046 // THIS ENTIRE SECTION might never be necessary if it's true that GetAsyncKeyState() and
2047 // GetKeyState() can retrieve the logical mouse button state on Windows NT/2000/XP, which are
2048 // the only OSes that matter for this purpose because the hooks aren't supported on Win9x.
2049 KBDLLHOOKSTRUCT &event = *(PMSDLLHOOKSTRUCT)lParam; // For convenience, maintainability, and possibly performance.
2050 switch (wParam)
2051 {
2052 case WM_LBUTTONUP: g_mouse_buttons_logical &= ~MK_LBUTTON; break;
2053 case WM_RBUTTONUP: g_mouse_buttons_logical &= ~MK_RBUTTON; break;
2054 case WM_MBUTTONUP: g_mouse_buttons_logical &= ~MK_MBUTTON; break;
2055 // WM_NCXBUTTONUP is a click in the non-client area of a window. MSDN implies this message can be
2056 // received by the mouse hook but it seems doubtful because its counterparts, such as WM_NCLBUTTONUP,
2057 // are apparently never received:
2058 case WM_NCXBUTTONUP:
2059 case WM_XBUTTONUP:
2060 g_mouse_buttons_logical &= ~( (HIWORD(event.mouseData)) == XBUTTON1 ? MK_XBUTTON1 : MK_XBUTTON2 );
2061 break;
2062 case WM_LBUTTONDOWN: g_mouse_buttons_logical |= MK_LBUTTON; break;
2063 case WM_RBUTTONDOWN: g_mouse_buttons_logical |= MK_RBUTTON; break;
2064 case WM_MBUTTONDOWN: g_mouse_buttons_logical |= MK_MBUTTON; break;
2065 case WM_NCXBUTTONDOWN:
2066 case WM_XBUTTONDOWN:
2067 g_mouse_buttons_logical |= (HIWORD(event.mouseData) == XBUTTON1) ? MK_XBUTTON1 : MK_XBUTTON2;
2068 break;
2069 }
2070#endif
2071 }
2072 else // Our caller is the keyboard hook.
2073 {
2074 KBDLLHOOKSTRUCT &event = *(PKBDLLHOOKSTRUCT)lParam;
2075
2076 bool is_ignored = IsIgnored(event.dwExtraInfo);
2077 if (!is_ignored)
2078 {
2079 if (kvk[aVK].pForceToggle) // Key is a toggleable key.

Callers

nothing calls this directly

Calls 7

IsIgnoredFunction · 0.85
SuppressThisKeyFuncFunction · 0.85
CollectInputFunction · 0.85
UpdateKeybdStateFunction · 0.85
ResetHookFunction · 0.85
KeyEventMenuMaskFunction · 0.85
InputLevelFromInfoFunction · 0.85

Tested by

no test coverage detected