Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Script to only run when window is active


  • Please log in to reply
1 reply to this topic
abgar
  • New members
  • 2 posts
  • Last active: Oct 08 2015 08:31 AM
  • Joined: 28 Sep 2015

Hi guys,  I use the below script as a bunnyhop script for CounterStrike Source.  I've added the process_watcher so that when the game is quit, the script stops automatically.

What I'm wondering though is, is it possible to have the script so that it only works while i'm actually playing the game?

i.e. so that if I Alt-Tab out of the game, the script pauses, but when Alt-Tab back INTO the game, the script continues?
 

 

*space::
Loop
{
GetKeyState,state,space,P
if state = U
break

Send,{space}
Sleep,20
}

SetTimer process_watcher, 100

process_watcher:
    Process Exist, hl2.exe
    If ErrorLevel = 0
        Exitapp
return



Shadowpheonix
  • Members
  • 268 posts
  • Last active:
  • Joined: 10 Feb 2014

Here is one way to do it...

SetTimer process_watcher, 100  ; I moved this to the top of the script to make sure it actually executes.
 
*space::
Loop
{
    Sleep,20    ; Moved this to the start of the loop so that it applies regardless of what window is active
    IfWinNotActive, ahk_exe hl2.exe    ; Check if HL2.EXE is the active window.
        Continue    ; HL2.EXE is not active, so skip the rest of the loop (without breaking out of the loop).
    GetKeyState,state,space,P
    if state = U
        break
    Send,{space}
}
Return  ; Added this as it is good practice to separate your hotkeys & sub-routines.
 
process_watcher:
    Process Exist, hl2.exe
    If ErrorLevel = 0
        Exitapp
return