0

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 !Tab::Return

1
  • I added it is there a way to disable it Feb 10, 2020 at 10:07

1 Answer 1

1

There is 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.

But since sending Alt+Tab is troublesome, you want rather AltTab more than any alternative. The problem is:

AltTab and ShiftAltTab are two of the special commands that are only recognized when used on the same line as a hotkey.

They are not recognized inside the If statement.

Fortunately there is also #If:

#If is 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)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .