How can I make a script run when a program opens?
I know nothing of coding and I would like a specific code to be ran when I open a program. I have heard of batch files but I can't seem to get them to work, and is there a way to do it via ahk?
Thanks
ifwinactive or batch file?
-
- Posts: 8
- Joined: 18 Feb 2018, 19:10
Re: ifwinactive or batch file?
You have to have an already running script to detect a programs open window on the fly.
Click on every command within this code box to get further details! Happy scripting.
Code: Select all
SetTitleMatchMode, 2
SetTimer, Check, % 1000 * 1 ; check every second ( = 1000ms)
Return
Check:
If WinActive(" - Notepad")
SoundBeep ; beep if a Notepad window is (still) open
Return
Re: ifwinactive or batch file?
also an example with PID and GUI
start ahk-script > start notepad and controlsend text to notepad
when close ahk-script > close also notepad
start ahk-script > start notepad and controlsend text to notepad
when close ahk-script > close also notepad
Code: Select all
; example =
; start notepad end controlsend to it
; close this script > notepad close also
;---------------------------------------------
#warn
setworkingdir,%a_scriptdir%
pr=notepad.exe
sc=ahk_exe notepad.exe
IfWinNotExist,%sc%
{
Run, %pr%,,,pid2
scx:= "ahk_pid " . PID2
WinWait,%scx%
}
IfWinNotActive ,%scx%,,WinActivate,%scx%
WinWaitActive,%scx%
controlsend,,Line1`nLine2`n,ahk_pid %pid2%
Gui,2:default
Gui,2: +alwaysontop
Gui,2:Color,Black
Gui,2: font,s12 cBlack,Lucida Console
Gui,2: add,button , x10 y10 w100 h26 gA1,TEST1
Gui,2:show,x1 y1 w140 h50,TEST
return
a1:
msgbox, 262208,Button-Test1 ,You click on button test1
return
2Guiclose:
Gui,2:submit,nohide
Process ,Exist, %pid2%
if (ErrorLevel == pid2)
Process, Close, %pid2%
exitapp
;=============== END test script =====================
Who is online
Users browsing this forum: No registered users and 185 guests