I need to have the ability to turn Alt + Tab on and off. Is there a way to do that via AHK. I know how to disable it but reverse that is not possible i think.
I disable it user
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
If. In general you can use it to conditionally run some code. A straightforward idea is to send Alt+Tab or nothing, depending on some condition.
ShiftAltTabare two of the special commands that are only recognized when used on the same line as a hotkey.
They are not recognized inside the
Fortunately there is also
#Ifis positional: it affects all hotkeys and hotstrings physically beneath it in the script. […] To turn off context sensitivity, specify
#If[…] but omit all the parameters.
This way we can conditionally apply your known way to disable the key and we don't even need
AltTab in the script:
#If (GetKeyState("ScrollLock", "T")) !Tab:: Return +!Tab:: Return ; to disable Shift+Alt+Tab as well #If
Now ScrollLock is like "AltTabLock". It locks Alt+Tab.
Adjust the condition to your needs. A variable may be useful. E.g. this will make F10 the toggle key:
#If (disable==1) !Tab:: Return +!Tab:: Return #If F10:: disable:=NOT(disable)