Tuesday, February 17, 2015

autohotkey - AHK - set a subroutine to trigger another subroutine by pressing its hotkey


Is it possible in AHK to set a subroutine to trigger another subroutine by pressing its hotkey (not goSub, or GoTo)


I have a script like this...


#If (WinActive("ahk_class XXX") || WinActive("ahk_class YYY")) && !GetKeyState("Space", "P")
8:: msgbox you hit 8
7:: msgbox you hit 7
6:: msgbox you hit 6
5:: msgbox you hit 5
4:: msgbox you hit 4
3:: msgbox you hit 3
2:: msgbox you hit 2
1:: msgbox you hit 1

and I would like another hotkey g:: to trigger the 8 hotkey from within the AHK script, I know I could GoTo, but is it possible to trigger a hotkey instead?


Currently I have tried...


g Up::
SendInput{8 Down}{8 Up}
;SendInput {8 Down}{8 Up}
Return
with no result, it doesn't trigger the `8::` subroutine.

is it possible? thanks advanced.


If not possible, I have tried using GoTo, but this doesn't work...


$g::
GoTo, GoGroup1
Sleep 50
GoTo, ToolPset2
Return
GoGroup1:
some clicks
Return
ToolPset2:
some clicks
Return

cuz when pressing g it does Go to group1, but then it doesn't GoTo ToolPset2, why???


Answer



If you use GoSub instead of Goto, it should work.
Basically: Gosub returns, but Goto never comes back.


$g::
GoSub, GoGroup1
Sleep 50
GoSub, ToolPset2
Return
GoGroup1:
MsgBox 1
Return
ToolPset2:
MsgBox 2
Return

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...