I want to use AutoHotKey to disable Alt+F4 when they are pressed within 0.05 seconds of each other. Otherwise, I'd like it to work as normal.
Explanation:
My Lenovo Yoga 2 Pro has alternate functions for the function keys.
For example: "F3" is mapped to volume+, "F4" is mapped to "close active window"
There are two modes:
- Old-school mode: F3 just acts as F3, and you must hold Fn+F3 key to activate volume+
- New-school mode: Pressing F3 activates volume+, and Fn+F3 will do the normal F3.
In either mode, I run the risk of closing my active window when I go to use volume+ because they are too close, which is very problematic. Note that AutoHotKey cannot detect the Fn key, thus I cannot use that to solve my issue.
The image below shows the AutoHotKey Key History tool. In New-school mode, I typed "asdf" and then pressed "F4" which is "close active window". You can see this actually simulates ALT+F4, and there is a very short duration between ALT and F4...
I'm thinking that I could disable this "close active window" function by having AutoHotKey interrupt an ALT+F4 combo when there is less than 0.05 seconds between the two keys. Can this be done?
Edit: In response to Blauhirn's code, here is the original, edited for a shorter wait duration, (from 50 to 10). It works most of the time, though 1/10 times the window is still cosed:
~alt::
hotkey, alt, off
hotkey, !F4, doNothing, on
sleep, 10
hotkey, !F4, doNothing, off
while(getKeyState("alt"))
sleep, 1
hotkey, alt, on
return
doNothing:
return
Here is a change I thought would fix my focus issue by sending a 2nd Alt when the "close active window" was detected:
doNothing:
send {LAlt}
return
However, the 2nd Alt is not sent. It IS sent when the delay is above 40ish, however I find that is way too long, and in turn it interferes with my manual use of Alt+F4.