Exiting two scripts ar once with the same hotkey Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
soheill0098
Posts: 69
Joined: 01 Sep 2020, 12:28

Exiting two scripts ar once with the same hotkey

Post by soheill0098 » 18 Mar 2023, 09:57

I have two scripts in ahk format and I want to exit both of them with shift + z hotkey at once. So I added

Code: Select all

!z::ExitApp
at the end of each scripts.But the problem is I want to exit both scripts at once when I press the keys but now I have to press it twice. Can you please help me to fix it?

User avatar
mikeyww
Posts: 26871
Joined: 09 Sep 2014, 18:38

Re: Exiting two scripts ar once with the same hotkey

Post by mikeyww » 18 Mar 2023, 10:04

Hello,

Having two scripts with the same hotkey, running at the same time, is a bad idea. It is also not necessary for your goal, because you can simply use :arrow: WinClose to close another window.

Learn about modifier keys

Code: Select all

#Requires AutoHotkey v2.0

!z:: {  ; ALT-Z = Close another script, and exit
 otherScript := A_ScriptDir '\r.ahk'
 DetectHiddenWindows True
 Try WinClose otherScript ' ahk_class AutoHotkey'
 SoundBeep(1500), ExitApp()
}

soheill0098
Posts: 69
Joined: 01 Sep 2020, 12:28

Re: Exiting two scripts ar once with the same hotkey

Post by soheill0098 » 18 Mar 2023, 10:25

mikeyww wrote:
18 Mar 2023, 10:04
Hello,

Having two scripts with the same hotkey, running at the same time, is a bad idea. It is also not necessary for your goal, because you can simply use :arrow: WinClose to close another window.

Learn about modifier keys

Code: Select all

#Requires AutoHotkey v2.0

!z:: {  ; ALT-Z = Close another script, and exit
 otherScript := A_ScriptDir '\r.ahk'
 DetectHiddenWindows True
 Try WinClose otherScript ' ahk_class AutoHotkey'
 SoundBeep(1500), ExitApp()
}
Hello, thanks for the help! But I faced the error

Code: Select all

Parameter #1 invalid
It refers to the line

Code: Select all

DetectHiddenWindows True

Not sure what I should do.
Last edited by soheill0098 on 18 Mar 2023, 10:45, edited 1 time in total.

User avatar
mikeyww
Posts: 26871
Joined: 09 Sep 2014, 18:38

Re: Exiting two scripts ar once with the same hotkey

Post by mikeyww » 18 Mar 2023, 10:26

Run my script by itself first, with no other code, and no changes. It assumes that you are using AHK v2. Use the last version that I posted (above). Use copy and paste to paste the text into your script file. If it fails, then post your exact script in a new reply below, and include a screenshot of the error message.

soheill0098
Posts: 69
Joined: 01 Sep 2020, 12:28

Re: Exiting two scripts ar once with the same hotkey

Post by soheill0098 » 18 Mar 2023, 10:44

mikeyww wrote:
18 Mar 2023, 10:26
Run my script by itself first, with no other code, and no changes. It assumes that you are using AHK v2. Use the last version that I posted (above). Use copy and paste to paste the text into your script file. If it fails, then post your exact script in a new reply below, and include a screenshot of the error message.
Oh I thought I had v2. And now I see version 2 is realesed lately! I have some connection issues with my PC (I live in Iran :shock: ). I will inform you the result when I do the process. Thanks again! Bye for now.

User avatar
mikeyww
Posts: 26871
Joined: 09 Sep 2014, 18:38

Re: Exiting two scripts ar once with the same hotkey  Topic is solved

Post by mikeyww » 18 Mar 2023, 10:53

You are posting in the v2 forum.

V1 is below.

Code: Select all

#Requires AutoHotkey v1.1.33
!z::  ; ALT-Z = Close another script, and exit
otherScript := A_ScriptDir "\r.ahk"
DetectHiddenWindows On
WinClose % otherScript " ahk_class AutoHotkey"
SoundBeep 1500
ExitApp

soheill0098
Posts: 69
Joined: 01 Sep 2020, 12:28

Re: Exiting two scripts ar once with the same hotkey

Post by soheill0098 » 30 Mar 2023, 19:02

mikeyww wrote:
18 Mar 2023, 10:53
You are posting in the v2 forum.

V1 is below.

Code: Select all

#Requires AutoHotkey v1.1.33
!z::  ; ALT-Z = Close another script, and exit
otherScript := A_ScriptDir "\r.ahk"
DetectHiddenWindows On
WinClose % otherScript " ahk_class AutoHotkey"
SoundBeep 1500
ExitApp
Thanks a lot sir! It was my mistake. Also glad to see there is a v2 of AHK.

Post Reply

Return to “Ask for Help (v2)”