Resetting keypresses in a sequence back to the first key…

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
SmithyZoomZoom
Posts: 111
Joined: 23 Aug 2019, 23:32

Resetting keypresses in a sequence back to the first key…

Post by SmithyZoomZoom » 14 Oct 2021, 01:11

Hello everyone:

I am an AutoHotkey user with a fine motor skill disability who uses AutoHotkey to make various computer tasks 10 times easier. Seriously, this program a lifesaver! I have one key set up to press other keys in a sequence. The script looks like this:

Code: Select all

]::
key++ ; this will help cycling through the keys depending on its value
if key = 1
{
Send, {q}
ToolTip 2 – R, 1400, 1000
}
else if key = 2
{
Send, {r}
ToolTip 3 – Switch, 1400, 1000
}
else if key = 3
{
Send, {F3}
ToolTip 4 – Q, 1400, 1000
}
else if key = 4
{
Send, {q}
ToolTip
Sleep 400
Send, {F3}
key = 0 ; return to the original state... do this on the last hotkey you would like to send
}
return
What I would like to do is make a keypress of this button at any time:
[
…then key = 0, therefore we resetting the cycle no matter which section of the script I am currently activating, pressing [ means the script will start over at its starting point. I think I have to make some kind of loop?

Any help would be appreciated.

Thank you.

Rohwedder
Posts: 7550
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Resetting keypresses in a sequence back to the first key…

Post by Rohwedder » 14 Oct 2021, 02:31

Hallo,
this?:

Code: Select all

]::
key++ ; this will help cycling through the keys depending on its value
Switch, key
{
Case 1:
	Send, {q}
	ToolTip 2 – R, 1400, 1000
Case 2:
	Send, {r}
	ToolTip 3 – Switch, 1400, 1000
Case 3:
	Send, {F3}
	ToolTip 4 – Q, 1400, 1000
Case 4:
	Send, {q}
	ToolTip
	Sleep 400
	Send, {F3}
	key = 0 ; return to the original state... do this on the last hotkey you would like to send
}
return
0::
ToolTip
key = 0
Return

SmithyZoomZoom
Posts: 111
Joined: 23 Aug 2019, 23:32

Re: Resetting keypresses in a sequence back to the first key…

Post by SmithyZoomZoom » 14 Oct 2021, 16:56

I like your Hallo. Just wanted to say your script was flawless and thank you for your stupendous skills. The only thing I ended up changing was the 0:: into a [:: to initiate the script. Thanks again! Could I ask you to explain what exactly you did but only if you have time?

Rohwedder
Posts: 7550
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Resetting keypresses in a sequence back to the first key…

Post by Rohwedder » 15 Oct 2021, 01:29

I just found Switch Case blocks nicer than If Else blocks.

SmithyZoomZoom
Posts: 111
Joined: 23 Aug 2019, 23:32

Re: Resetting keypresses in a sequence back to the first key…

Post by SmithyZoomZoom » 15 Oct 2021, 10:25

I don't suppose you or one of the other readers could please say more about how switch case works because I've never seen that before? I looked it up on YouTube. This is the best video I could find but it has no explanations:
https://www.youtube.com/watch?v=Yc4V_ev2498

Thank you for your time.

Rohwedder
Posts: 7550
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Resetting keypresses in a sequence back to the first key…

Post by Rohwedder » 16 Oct 2021, 01:25

Learning with videos may be good for dyslexics. For standard people I recommend the Autohotkey manual.
https://www.autohotkey.com/docs/commands/Switch.htm
Pros: Everyone uses their optimal reading and thinking speed. The example scripts can be easily copied and tested.

Post Reply

Return to “Ask for Help (v1)”