Disabling ALT - TAB only while a specific application is running using auto hot key

3k views Asked by At

Id like to be able to run an .exe that launches a game, disables the use of Alt-Tab(Preferably only when the game is in focus), then waits for me to exit the game manually before terminating the script.

So far all I have is

run C:\Program Files (x86)\Steam\steamapps\common\Counter-Strike Global Offensive

!Tab::return

But I can't seem to figure out how to disable it only when the screen is focused on the game, or how to wait for me to close the game before re-enabling it.

Also I'm not entirely sure if this would allow me the use of tab while Im playing the game. I want to be able to press ALT and TAB at the same time as they both have functions, just not switch windows.

1

There are 1 answers

2
JPGInc On

Here is how I would do it. As MLC said use #ifWinActive

;run your program, save the proccess ID
Run, notepad, , , thePid
;add that process to a group
GroupAdd, blockAltTab, % "ahk_pid " thePid
;wait for the process to close and exit
Process, waitClose, %thePid%
ExitApp

;if a window from the blockAltTab group is in the foreground then block alt+tab
#IfWinActive, ahk_group blockAltTab
!Tab::return
;clear the blockAltTab group restriction for any other hotkeys
#IfWinActive