Can i enable Alt + Tab when a key is pressed

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

jojo osinga

Posted 2020-02-10T09:08:59.477

Reputation: 21

I added it is there a way to disable it – jojo osinga – 2020-02-10T10:07:01.833

Answers

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)

Kamil Maciorowski

Posted 2020-02-10T09:08:59.477

Reputation: 38 429