1
votes

First, Here's the code

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance Force
IfWinNotExist, ahk_exe VisualBoyAdvance.exe
{
    Run, VisualBoyAdvance.exe, D:\Games\GAMEBOY ADVANCE (.gba)\GBA\emu
    WinWait, ahk_exe VisualBoyAdvance.exe
    WinActivate, ahk_exe VisualBoyAdvance.exe
    return
}
WinActivate, ahk_exe VisualBoyAdvance.exe
sleep, 1000
MouseClick,,22,40
sleep,100
MouseClick,,116,257
sleep,100
MouseClick,,342,312
sleep,100
MouseClick,,179,16
return
Joy4::
MouseClick,,77,43
sleep, 100
MouseClick,,111,105
sleep, 100
MouseClick,,263,217
sleep, 100
MouseMove, 1380, 251
return
Joy1::
Send, {Shift Down}
Sleep, 100
Send, {F1}
Sleep, 100
Send, {Shift Up}
Return
Joy12::Send, {F1}
return
;LCtrl::
;ExitApp

It's basically open VisualBoyAdvance from the top of the recent list on VBA, i wanted to whenever i close the VBA, the script closed as well.. i've tried lot of method on the AutoHotKey Website, like : Process, WaitClose, exwfile.exe ExitApp Return Or

RunWait, calc
ExitApp

or

Run, C:\Program Files (x86)\Sonos\Sonos.exe
WinWait, ahk_exe Sonos.exe
SetTimer,Sonos,100

Sonos:
IfWinNotExist, Sonos
     ExitApp
Return

but none of them works

please help me thank you

2

2 Answers

1
votes

Try using WinWaitClose followed by ExitApp:

// [...]
sleep,100
MouseClick,,179,16
WinWaitClose, ahk_exe VisualBoyAdvance.exe
ExitApp
Return

// [...]
-1
votes
IfWinNotExist, ahk_exe Sonos.exe