Multiple scripts for one key: how to implement? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
AHMe
Posts: 3
Joined: 16 Aug 2017, 06:08

Multiple scripts for one key: how to implement?

16 Aug 2017, 06:23

Hi all!

Thanks in advance for any efforts people put in to help me!

I have the code below (I'll call it the "NumpadDown" code) which has been working great for me :).

Code: Select all

NumpadDown::
	
	 {
	   KeyWait, NumpadDown
	   KeyWait, NumpadDown, D T.1
	   If (!ErrorLevel)
		{
		  goto, subNumpadDown
		}
		else {
			; Do this if key just single pressed
			WinMinimize, A
		}
	 }
	return

	subNumpadDown:	;come here if double press
	 {
		
		Send {alt down}{2 down}
		Sleep, 5
		Send {2 up}{alt up}
		Sleep, 5
	 }
Return
But I now also want to use the code below (I'll call it the "NumpadAdd & NumpadDown" code).

Code: Select all

NumpadAdd & NumpadDown::

KeyWait NumpadAdd
KeyWait NumpadDown

	Send, ^d
                
Return
So I added the "NumpadAdd & NumpadDown" code, but when I ran the "NumpadAdd & NumpadDown" code, it ran the "NumpadAdd & NumpadDown" code and then continued on and ran the "NumpadDown" code. This is not what I wanted it to do.

What I wanted it to do was just run the "NumpadAdd & NumpadDown" code. And of course, when I run the "NumpadDown" code, I don't want it to run the "NumpadAdd & NumpadDown" code.

If anyone has any ideas on how to get the two codes to run independently, that would be much appreciated! :)

Thank you!
AHMe
Posts: 3
Joined: 16 Aug 2017, 06:08

Re: Multiple scripts for one key: how to implement?  Topic is solved

21 Aug 2017, 21:27

I've found a fix/workaround!

Thanks to TAC109 in the post here:
https://autohotkey.com/boards/viewtopic.php?t=35043

The 'Reloads' in the code below, "Replaces the currently running instance of the script with a new one" (https://autohotkey.com/docs/commands/Reload.htm)

Now my codes look like below, and so far, so good.

I'm hoping that the "Reload" doesn't come back to bite me in another way though. We'll see.

Code: Select all

NumpadDown::
	
	 {
	   KeyWait, NumpadDown
	   KeyWait, NumpadDown, D T.1
	   If (!ErrorLevel)
		{
		  goto, subNumpadDown
		}
		else {
			; Do this if key just single pressed
			WinMinimize, A
		}
	 }
	return

	subNumpadDown:	;come here if double press
	 {
		Send {alt down}{2 down}
		Sleep, 5
		Send {2 up}{alt up}
		Sleep, 5
		Reload
	 }
Return

Code: Select all

NumpadAdd & NumpadDown::

	KeyWait NumpadDown
	Send, ^d
	Reload
	
Return
Rohwedder
Posts: 7644
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Multiple scripts for one key: how to implement?

22 Aug 2017, 01:47

Hallo,
if you change

Code: Select all

NumpadAdd & NumpadDown::
to

Code: Select all

NumpadDown & NumpadAdd::
and press the combination in this order, you do not need reloads.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mankvl, OrangeCat and 323 guests