How to trigger a hotkey from another scirpt

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
proferk1
Posts: 3
Joined: 28 Jan 2023, 05:55

How to trigger a hotkey from another scirpt

Post by proferk1 » 28 Jan 2023, 06:16

I'm using a program (https://github.com/lal12/macroMyKBD) that uses a custom driver to execute a autohotkey script (keydown_a.ahk) when the "down" event for the "a" key fires on my second keyboard
and execute keyup_a.ahk when the "up" event for it fires. In these scripts I am wrapping the "a" key in F24 (like a modifier key). and in another script (main.ahk) I am listening to those keys that have been wrapped in F24.
The program I am using blocks the actual events from firing, so that I can send the events manually in the keydown_a.ahk and keyup_a.ahk and wrap them in F24.
However, for some reason, the keydown_a.ahk and keyup_a.ahk don't seem to trigger the hotkeys I've defined in main.ahk. How do I fix this?


main.ahk:

Code: Select all

#if GetKeyState("F24")
f::MsgBox, Test ; This hotkey doesn't get triggered for some reason
keydown_a.ahk:

Code: Select all

Send, {F24 down}{f down}
keyup_a.ahk:

Code: Select all

Send, {f up}{F24 up}

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

Re: How to trigger a hotkey from another scirpt

Post by mikeyww » 28 Jan 2023, 06:36

SendLevel allows to trigger hotkeys and hotstrings of another script, which normally would not be the case.
https://www.autohotkey.com/docs/v1/lib/SendLevel.htm#ExBasic

proferk1
Posts: 3
Joined: 28 Jan 2023, 05:55

Re: How to trigger a hotkey from another scirpt

Post by proferk1 » 28 Jan 2023, 12:37

Okay, that does work. but I've encountered a similar issue in a different script that I don't think is worth making a new post for.

Code: Select all

LCtrl::SC071
SC071::msgbox, test
When I press LCtrl, it does remap it to SC071, however the msgbox that is mapped to SC071 does not trigger. The SendInput you mentioned did not work in this case, and I'm pretty sure that's because I'm not actually using Send in here.
Anyways so how do I make the attached code snippet work? (Btw, do not ask why I'm doing things the way I'm doing, it's for a very good reason.)

proferk1
Posts: 3
Joined: 28 Jan 2023, 05:55

Re: How to trigger a hotkey from another scirpt

Post by proferk1 » 28 Jan 2023, 12:55

proferk1 wrote:
28 Jan 2023, 12:37
The SendInput you mentioned did not work in this case
SendLevel*

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

Re: How to trigger a hotkey from another scirpt

Post by mikeyww » 28 Jan 2023, 15:53

Some sending methods will not trigger a hotkey, but the workaround would simply be calling a function or subroutine. I generally prefer that approach anyway, when the goal is not to send a key but to call another part of the script. That is the purpose of functions & subroutines.

Post Reply

Return to “Ask for Help (v1)”