How to call a hotkey in a second script from the first script ?

Ask gaming related questions (AHK v1.1 and older)
GoneFishing
Posts: 126
Joined: 20 May 2022, 16:17

How to call a hotkey in a second script from the first script ?

Post by GoneFishing » 07 Dec 2022, 12:31

I need to execute a hotkey in a second script which is called from within the first script. I can call the second script with the run command without an issue but this of course doesn't trigger the hotkey in the second script. I need to trigger the [ key in the second script.

Code: Select all

run, c:\Program Files (x86)\The name of the Game\Path of Game\logs\SecondScript.ahk
Hotkey command
How do I get the first script to trigger the hotkey in the second script automatically without me having to press anything ?

ThePeter
Posts: 49
Joined: 25 Oct 2022, 05:57

Re: How to call a hotkey in a second script from the first script ?

Post by ThePeter » 07 Dec 2022, 13:14

Have you tried simply sending the key triggering the other hotkey?

Code: Select all

run, c:\Program Files (x86)\The name of the Game\Path of Game\logs\SecondScript.ahk
Sleep 100 
Send [

GoneFishing
Posts: 126
Joined: 20 May 2022, 16:17

Re: How to call a hotkey in a second script from the first script ?

Post by GoneFishing » 07 Dec 2022, 17:19

ThePeter wrote:
07 Dec 2022, 13:14
Have you tried simply sending the key triggering the other hotkey?

Code: Select all

run, c:\Program Files (x86)\The name of the Game\Path of Game\logs\SecondScript.ahk
Sleep 100 
Send [
That won't work as it thinks the Send [ is part of the first script. I need to trigger the [ hotkey in the second script automatically once the second script is started by the first one (and yes I did try the sleep command prior to posting. Should have mentioned that).

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: How to call a hotkey in a second script from the first script ?

Post by swagfag » 07 Dec 2022, 18:24

Code: Select all

; in first.ahk
SendLevel 1 ; or whichever value is higher than the #InputLevel of the hotkey in second.ahk
SendInput [ ; or SendEvent, but not SendPlay
should work in most cases, but this is a crappy unreliable way of IPC between scripts. u should probably just SendMessage/OnMessage() instead

GoneFishing
Posts: 126
Joined: 20 May 2022, 16:17

Re: How to call a hotkey in a second script from the first script ?

Post by GoneFishing » 08 Dec 2022, 09:54

swagfag wrote:
07 Dec 2022, 18:24

Code: Select all

; in first.ahk
SendLevel 1 ; or whichever value is higher than the #InputLevel of the hotkey in second.ahk
SendInput [ ; or SendEvent, but not SendPlay
should work in most cases, but this is a crappy unreliable way of IPC between scripts. u should probably just SendMessage/OnMessage() instead
While SendMessage/OnMessage is the more robust method it's beyond my scripting ability to do. I'll give SendLevel and SendInput a try.
I don't quite follow the comment about SendLevel - how do I determine what value O need to put in for SendLevel ?

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: How to call a hotkey in a second script from the first script ?

Post by swagfag » 08 Dec 2022, 10:05

if u have to ask, then 1 will probably suffice. read SendLevel/#InputLevel docs

GoneFishing
Posts: 126
Joined: 20 May 2022, 16:17

Re: How to call a hotkey in a second script from the first script ?

Post by GoneFishing » 08 Dec 2022, 12:54

swagfag wrote:
08 Dec 2022, 10:05
if u have to ask, then 1 will probably suffice. read SendLevel/#InputLevel docs
SendLevel 1 worked. It gives me time to read up on the documentation now in case I want to try my hand at the better syntax. Thanks for the help :+1:

Post Reply

Return to “Gaming Help (v1)”