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

0

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???

litu16

Posted 2017-01-06T05:54:41.187

Reputation: 143

Answers

0

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

vafylec

Posted 2017-01-06T05:54:41.187

Reputation: 136

thanks man, could you please check out this question?? http://superuser.com/questions/1164320/autohotkey-how-to-launch-a-ahkscript-from-within-another-ahkscript thanksAdvanced.

– litu16 – 2017-01-06T23:41:57.703

It says the question was removed!? Btw I wrote that script for hotkeys that removed the menu bars, did the key presses respond smoothly? – vafylec – 2017-01-07T01:22:33.223

Normally you send this message to either suspend or unsuspend a script, (it toggles suspend on/off): PostMessage, 0x111, 65404,,, ahk_id %hWnd%. -- This link explains how to retrieve the suspend on/off status of a script: https://autohotkey.com/board/topic/89284-turn-all-scripts-on-and-off/page-2#entry565650

– vafylec – 2017-01-07T02:08:39.207

yes thanks, that suspend unsuspend its done, I haven't try this question respond yet, Ill do it ASAP, thanks agian. btw can a AHK script flip horizontally (mirror horizontally) my main screen?? thanks advanced. http://superuser.com/questions/1164910/can-an-ahkscript-flip-horizontally-mirror-horizontally-my-main-screen-thanks

– litu16 – 2017-01-08T21:49:53.667

I don't know about flipping the screen horizontally. Do you have a utility that can do this? Then maybe AutoHotkey can tell the utility to do it. – vafylec – 2017-01-08T23:59:22.617

No, I'm looking for an autohotkey script that could do that, please superuser community help me on this, thankss – litu16 – 2017-01-09T00:24:22.260

-- AutoHotkey usually achieves things via the Winapi. I don't know if the Winapi can do this. -- Otherwise if you know of a utility that can do this, then you might be able to communicate with it via AutoHotkey. -- (I can't help you any more than that regarding flipping the screen horizontally.) -- Are you working on a big project? Do you need it for gaming or something? – vafylec – 2017-01-09T00:56:17.460

nope I'm just an illustrator n an a bit of programmer xD – litu16 – 2017-01-09T02:56:08.313