No, I can't keep JoyToKey running because I only need it to run for 2 emulators that won't allow you to remap multiple controls for the same button (ZSNES and KegaFusion). The profiles for JoyToKey for the 2 emulators would clash with each other and clash with other emulators as well.
KegaFusion is making it more annoying because it will not allow you to remap emulator functions.
I got the script to work half way right. It will open both JoyToKey and the AutoHotKey scrip on eumlator launch, but will only close the AutoHotKey script and not JoyToKey.
;Parsing
Local $count = StringInStr($CmdLineRaw, ".exe", 0, 1, 1)
local $app = StringLeft ( $CmdLineRaw, $count + 4 )
local $command = StringTrimLeft( $CmdLineRaw, $count + 4 )
if not $command then exit 0
;run your 2d app
local $PID = Run ('D:\Emulators\Consoles\Sega Genesis, SegaCD & 32X KegaFusion 3.64 x86\JoyToKey(kega).exe')
local $PID = Run ('D:\Emulators\Consoles\Sega Genesis, SegaCD & 32X KegaFusion 3.64 x86\kega_script.exe')
;run emulator and wait for close
Runwait ( '"' & $app & '" ' & $command )
;close the 2d app
ProcessClose ( $PID )
ProcessClose ( $PID )
Exit 0