Script A Runs B on Exit, B Runs A on Exit, Never Works

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
gibenedek
Posts: 53
Joined: 20 Sep 2020, 19:51

Script A Runs B on Exit, B Runs A on Exit, Never Works

Post by gibenedek » 20 May 2022, 21:21

Hello, Topic Says it all. Whenever I try this, either by Label or Function, something doesnt work right. To get in to detail, Script A is my Hotkey Script. I have a Hotkey to launch the hotkey script in Script B. When Hotkeys are on, I need the Hotkey Launcher Script to turn off.

End Result is No matter what, I want ^!=:: to run my Hotkey Script. Hotkey script is reload itself, easy. But the Hotkey Launcher Script either doesnt turn on, or they both start a cycle of ending eachother. Pleeaas, Halp

Script A is 1000+ Lines, but the code in Question is:

Code: Select all


OnExit, ScriptNKLauncher
...
...
...
/*     OnExit Label                                                                     
*/ScriptNKLauncher:
Run C:\[Data] My Files\AutoHotkey\Nova Keys\Nova Keys Launcher Script.ahk
Exitapp
return		 ; <---- Redundant, I Know

And Script B is Simple:

Code: Select all



#SingleInstance, Force
OnExit, RunNovaKeys

>^!=:: 
Run C:\[Data] My Files\AutoHotkey\Nova Keys\Nova Keys.ahk
;~ ExitApp
return

RunNovaKeys:
Run C:\[Data] My Files\AutoHotkey\Nova Keys\Nova Keys.ahk
Exitapp



Rohwedder
Posts: 7614
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Script A Runs B on Exit, B Runs A on Exit, Never Works

Post by Rohwedder » 21 May 2022, 03:00

Hallo,
this way you make sure that either Script1.ahk or Script2.ahk is running.

Code: Select all

; Script1.ahk
#SingleInstance Force
SetTitleMatchMode, 2
DetectHiddenWindows, On
WinWaitClose, Script2.ahk ahk_class AutoHotkey,, 1
DetectHiddenWindows, Off
IF ErrorLevel
	ExitApp
Else
	OnExit, RunScript2
ToolTip,% A_ScriptName ;Test
q:: ;Toogle scripts
RunScript2:
Run Script2.ahk
ExitApp

Code: Select all

; Script2.ahk
#SingleInstance Force
SetTitleMatchMode, 2
DetectHiddenWindows, On
WinWaitClose, Script1.ahk ahk_class AutoHotkey,, 1
DetectHiddenWindows, Off
IF ErrorLevel
	ExitApp
Else
	OnExit, RunScript1
ToolTip,% A_ScriptName ;Test
q:: ;Toogle scripts
RunScript1:
Run Script1.ahk
ExitApp

Post Reply

Return to “Ask for Help (v1)”