How to force trigger an hotkey with $ or #Usehook (thats in a different ahk file) Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
NorInd
Posts: 43
Joined: 03 May 2020, 04:23

How to force trigger an hotkey with $ or #Usehook (thats in a different ahk file)

09 Jul 2022, 11:50

For example,

Code: Select all

; in file AA
^r::
SendInput, ^i
return

; in file BB (another lib)
$^i::
ToolTip, % "AAA"
return
^r will not be able to trigger ^i in this case.

What if I do want to force trigger ^i with ^r?
When Im not able to modify file BB
  • (say, file BB is from another person's lib.
    I know this way of calling to another's lib/API is not good, but I just need it to work.)
Is this possible?
Last edited by NorInd on 10 Jul 2022, 15:15, edited 1 time in total.
NorInd
Posts: 43
Joined: 03 May 2020, 04:23

Re: How to force trigger an hotkey with $ or #Usehook

09 Jul 2022, 12:48

mikeyww wrote:
09 Jul 2022, 12:39
:arrow: Gosub can call any labeled subroutine. Example
Yeah, I did saw that in AHK documentation
One workaround is to use Gosub to jump directly to the hotkey's subroutine. For example: Gosub #LButton.

But the problem is, ^i is in a different .ahk file BB.
I dont think ^r in file AA can gosub to another file BB?

eg::

Code: Select all

; in file AA
^r:: gosub, $^i
; ==> Target label does not exist.

;  in file BB 
$^i:: ToolTip, AAA
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: How to force trigger an hotkey with $ or #Usehook

09 Jul 2022, 12:51

You can #Include the other file. That makes your script act as if the other script is contained within it.

Code: Select all

^r::Gosub, $^i
#Include %A_ScriptDir%\bb.ahk
NorInd
Posts: 43
Joined: 03 May 2020, 04:23

Re: How to force trigger an hotkey with $ or #Usehook

10 Jul 2022, 15:15

mikeyww wrote:
09 Jul 2022, 12:51
You can #Include the other file. That makes your script act as if the other script is contained within it.

Code: Select all

^r::Gosub, $^i
#Include %A_ScriptDir%\bb.ahk
Thats true... But I dont really want to do that... It introduces entangle between the files.
I rather that BB.ahk is running independent of AA.ahk...

behind motivation
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: How to force trigger an hotkey with $ or #Usehook (thats in a different ahk file)  Topic is solved

10 Jul 2022, 15:32

You can send a message from one script to another. :arrow: OnMessage

Also:

SendLevel:
SendLevel allows to trigger hotkeys and hotstrings of another script, which normally would not be the case.
NorInd
Posts: 43
Joined: 03 May 2020, 04:23

Re: How to force trigger an hotkey with $ or #Usehook (thats in a different ahk file)

10 Jul 2022, 17:25

SendLevel is the solution! Thanks for the reply.

Following code works::

Code: Select all

; in file AA
r:: 
SendLevel, 1 ; 1 is normally sufficient, as #InputLevel defaults to 0
SendInput, ^i
return

; in file BB
$^i:: ToolTip, AAA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Rxbie and 237 guests