Broadcast hotkey to other AHK script

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
imkira3
Posts: 84
Joined: 10 Jan 2023, 13:57
Contact:

Broadcast hotkey to other AHK script

27 Feb 2023, 10:57

AutoHotkey seems to be configured to ignore hotkeys from other running AHK scripts, so if 1.ahk was meant to trigger something on ^1 and 2.ahk did this:

Code: Select all

Send "^{1}"
it would not be detected. Now I find myself in a situation where I need to communicate with a v1 script that is much to complex to edit any further (see here for more details) but my problem would be effectively solved if I had my v2 script send the proper hotkey to this v1 script.
ntepa
Posts: 439
Joined: 19 Oct 2022, 20:52

Re: Broadcast hotkey to other AHK script

27 Feb 2023, 11:13

Code: Select all

SendLevel 1
Send "^{1}"
imkira3
Posts: 84
Joined: 10 Jan 2023, 13:57
Contact:

Re: Broadcast hotkey to other AHK script

27 Feb 2023, 11:16

I tried that, it's not working:

Code: Select all

SendLevel 1
Send "#{NumPad1}"
User avatar
mikeyww
Posts: 27370
Joined: 09 Sep 2014, 18:38

Re: Broadcast hotkey to other AHK script

27 Feb 2023, 11:30

Worked here.

Code: Select all

#Requires AutoHotkey v2.0
Send '^1'

Code: Select all

#Requires AutoHotkey v2.0
^1::MsgBox 123
imkira3
Posts: 84
Joined: 10 Jan 2023, 13:57
Contact:

Re: Broadcast hotkey to other AHK script

27 Feb 2023, 11:32

Does it work when sending #NumPad1 to a v1 script though? Does v1 script even support SendLevel? Not v1.1, I'm manipulating old v1 code
User avatar
mikeyww
Posts: 27370
Joined: 09 Sep 2014, 18:38

Re: Broadcast hotkey to other AHK script

27 Feb 2023, 11:34

Yes.

You can do this simple test by itself. Close your other scripts.

Code: Select all

#Requires AutoHotkey v1.1.33
#Numpad1::MsgBox 123

Code: Select all

#Requires AutoHotkey v2.0
Send '#{Numpad1}'
If other software uses the same hotkey, then a software conflict can occur.
Last edited by mikeyww on 27 Feb 2023, 11:37, edited 1 time in total.
imkira3
Posts: 84
Joined: 10 Jan 2023, 13:57
Contact:

Re: Broadcast hotkey to other AHK script

27 Feb 2023, 11:35

Like I said, I'm manipulating 1.0, not 1.1
This version here: https://raw.githubusercontent.com/AutoHotkey/AutoHotkey-v1.0_Builds/master/Builds/zip/AutoHotkey104805.zip
And I did test it ofc or I wouldn't have asked lol, it's not working
User avatar
mikeyww
Posts: 27370
Joined: 09 Sep 2014, 18:38

Re: Broadcast hotkey to other AHK script

27 Feb 2023, 11:41

That worked, too.

Code: Select all

#Requires AutoHotkey v2.0
Run 'd:\temp2\t\AutoHotkey.exe D:\temp2\temp1.ahk'
Sleep 2000
SoundBeep 1500
Send '#{Numpad1}'

Code: Select all

#Numpad1::MsgBox 123
image230227-1144-001_cr.png
Output
image230227-1144-001_cr.png (3.8 KiB) Viewed 710 times
Last edited by mikeyww on 27 Feb 2023, 11:46, edited 4 times in total.
imkira3
Posts: 84
Joined: 10 Jan 2023, 13:57
Contact:

Re: Broadcast hotkey to other AHK script

27 Feb 2023, 11:43

I don't understand then, why would the small-scale test work, but when I send it to this script, it fails to detect the keypress.
User avatar
mikeyww
Posts: 27370
Joined: 09 Sep 2014, 18:38

Re: Broadcast hotkey to other AHK script

27 Feb 2023, 11:44

Did you test my script, and found that it works at your end?
imkira3
Posts: 84
Joined: 10 Jan 2023, 13:57
Contact:

Re: Broadcast hotkey to other AHK script

27 Feb 2023, 11:47

I did and fact, and yes it worked but communicating with the big script I'm working with is obviously more complicated. There's something going on in that script I'm not seeing, but if small-scale tests work at least that's a start
User avatar
mikeyww
Posts: 27370
Joined: 09 Sep 2014, 18:38

Re: Broadcast hotkey to other AHK script

27 Feb 2023, 12:32

Yes. I am also not seeing something going on, because I am not seeing your script. Best of luck! If you shorten your script, you will find the problem.
imkira3
Posts: 84
Joined: 10 Jan 2023, 13:57
Contact:

Re: Broadcast hotkey to other AHK script

27 Feb 2023, 13:14

Ah, well I linked to it up above, but it's about 5000 lines lol
User avatar
mikeyww
Posts: 27370
Joined: 09 Sep 2014, 18:38

Re: Broadcast hotkey to other AHK script

27 Feb 2023, 13:41

I see no explicit hotkeys in that script. In terms of the hotkey command, you can use MsgBox, ListVars, etc. to understand what your script is doing. Shortening the script will make the work go faster.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: costelpislac, Descolada and 54 guests