Code: Select all
F2::XButton1
#IfWinActive File Explorer
F2::F5
- Download the attachment or create a script with the contents above and run it.
- Open a fresh instance of File Explorer (the default one on Windows). Ensure the title of the window matches the script. File Explorer is an arbitrary choice here.
- Verify that pressing F2 with File Explorer active refreshes the view.
- Click any other window that does not have elevated privileges, such as this browser window. Keep File Explorer at least partially visible.
- Hover the mouse cursor over File Explorer and then press F2.
100%
Expectation:
Due to the above script, the XButton1 press should activate File Explorer and input should work normally after that.
Actual behaviour:
The File Explorer window becomes active, but then stays active. Mouse clicks on other windows do not activate that window. Mouse clicks on the File Explorer window still act normally.
Keyboard input works normally. You can alt-tab to a different window and then provide keyboard input. From this state, clicking any window that is not the File Explorer window will cause the active window to become null (verified with the Win32 API GetForegroundWindow).
To easily restore the system to a normal state, press ctrl-alt-del to go to the secure desktop and then exit back to the regular desktop and click a couple times.
First noticed:
I've had this issue for approximately 1-2 years until now figuring out how to reproduce it, but as linked below, it seems someone had the same issue in 2012. I set this script up in about December 2019, so probably then.
Environment info:
Windows 11 21H2. Also happened throughout Windows 10 in the last 1-2 years.
AHK: 1.1.33.02, also reproduced in 1.1.33.10.
Reproduced in 2.0 beta 3 by changing the #IfWinActive line to #HotIf WinActive("File Explorer").
Speculation:
This appears to be caused by a weird interaction of rebinding to a standard mouse button, causing it to activate the window under the cursor, and then changing that bind once the new window is activated via the conditional hotkey. I speculate that the system gets an {XButton1 down}, but not an {XButton1 up}, and that this triggers Windows to get into the above state that IMO should never be allowed by the OS unless an app is specifically trying to keep a window active (so AHK isn't entirely to blame here).
With this in mind, I've made the following bandaid fix to my actual script, and it seems to work:
Code: Select all
F2::XButton1
#IfWinActive File Explorer
F2::
Send {XButton1 up}
Send {F5}
Return
Actual use case:
My real script is simply to rebind my extra 12 mouse buttons based on the active window. Synapse offers the ability to switch presets based on the active window, but appears to make server calls while doing so, ultimately freezing my cursor for around 1 second.
I bind these buttons to F13-F24 in Synapse and then use AHK to rebind those. By default, I have the mousepad4 button bound to XButton1 (back) and the mousepad6 button bound to XButton2 (forward). In MMOs, I rebind these to Numpad4 and Numpad6 respectively. Activating the game window by pressing mousepad4 or mousepad6 triggers this bug.
See also:
There is a help post from 2012 with what appears to be the same issue: https://www.autohotkey.com/board/topic/83560-mouse-keys-are-stuck-in-windows-after-execution-of-script/