only use macro when window is active?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ravena1
Posts: 62
Joined: 06 Sep 2017, 15:13

only use macro when window is active?

01 Mar 2022, 16:06

i want my macro to trigger only if the window is active/focus.. how to do that? thank you

Code: Select all

#NoEnv  
SendMode Input 
SetWorkingDir %A_ScriptDir%
SetKeyDelay, 0, 15 
SetMouseDelay, 30
#SingleInstance ,force


home::
WinGet, AhkPID, PID, A
WinGetClass, Chobobo, ahk_pid %AhkPID%
SplashTextOn,,, chobobo PID:%AhkPID% is saved
Sleep 2000
SplashTextOff


2::
If WinActive("ahk_pid %AhkPID%") & While GetKeyState("2", "P")
{
ControlSend, ahk_parent, 2, ahk_pid %AhkPID%
sleep, 30
ControlClick, x595 y412, ahk_pid %AhkPID%, , Left, 1, NA
sleep, 53
}
return






end::exitapp
Hardcoder
Posts: 278
Joined: 19 Feb 2022, 13:13
Location: Germany

Re: only use macro when window is active?

01 Mar 2022, 16:10

Surrounod it, or every hotkey/hotstring for that window in

Code: Select all

#If WinActive("ahk_exe ...") ; or ahk_class etc.
...
#If

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Spawnova and 137 guests