Making a key input rotate through four outputs

Get help with using AutoHotkey and its commands and hotkeys
Enterusernamehere
Posts: 3
Joined: 22 May 2019, 14:02

Making a key input rotate through four outputs

22 May 2019, 14:19

Hi, I've been dabbling with code with ahk but running into issues, namely with duplicate hotkeys

What I'm trying to do is have my space bar (or any other key) rotate through four different outputs after being pressed before looping back to the first again, below is my awful code, any pointers?

Code: Select all

Loop
{Space::Send,1
if IsDone {
    Space::Send,2
} 
if IsDone {
    Space::Send,3
} 
if IsDone {
    Space::Send,4
}
}
Sam_
Posts: 106
Joined: 20 Mar 2014, 20:24

Re: Making a key input rotate through four outputs

22 May 2019, 14:32

Code: Select all

Idx:=1
Space::
	Send,%Idx%
	Idx:=(Idx=4?1:Idx+1)
Return
or even shorter

Code: Select all

Idx:=0
Space::Send,% Idx:=(Idx=4?1:Idx+1)
both of which are just shorthand forms of

Code: Select all

Idx:=1
Space::
	Send,%Idx%
	If (Idx=4)
		Idx:=1
	Else
		Idx:=Idx+1
Return
Last edited by Sam_ on 22 May 2019, 14:40, edited 1 time in total.
Enterusernamehere
Posts: 3
Joined: 22 May 2019, 14:02

Re: Making a key input rotate through four outputs

22 May 2019, 14:39

Thanks for this! Could we go one step further and make the first button press into a mouseclick before going to A then 1 then 2 and back to mouseclick?
1-2-3-4 were placeholders, sorry I should have been more specific
Sam_
Posts: 106
Joined: 20 Mar 2014, 20:24

Re: Making a key input rotate through four outputs

22 May 2019, 15:02

Enterusernamehere wrote:
22 May 2019, 14:39
Thanks for this! Could we go one step further and make the first button press into a mouseclick before going to A then 1 then 2 and back to mouseclick?
1-2-3-4 were placeholders, sorry I should have been more specific
More like this?

Code: Select all

WhatToSend:=["A",1,2]
Idx:=0
Space::
	If (Idx=0)
		{
		MouseClick ; https://autohotkey.com/docs/commands/MouseClick.htm
		Idx+=1
		}
	Else If (Idx<3)
		{
		Send,% WhatToSend[Idx]
		Idx+=1
		}
	Else
		{
		Send,%  WhatToSend[Idx]
		Idx:=0
		}
Return
Either replace the values in the array WhatToSend with what you want to send, or replace WhatToSend[Idx] with whatever other variable whose contents you want to send.

Return to “Ask For Help”

Who is online

Users browsing this forum: flyingDman, Getfree, thebib622 and 138 guests