## Cycling keystrokes?

tgoVIPER
Posts: 12
Joined: 22 Apr 2018, 10:28

### Cycling keystrokes?

Does anyone have a quick piece of code to assign cycling of keystrokes to one key?
i.e. I'd like to press, say, the F7 key and each time I do it cycles between sending different single keys.

example:
I press F7 the first time // AHK sends '3'
I press F7 the second time // AHK sends '4'
I press F7 a third time // AHK sends '5'

then it resets so that if you pressed it a fourth time, it would start the above process over.

I'm at work right now and can't install AHK to give it a go here.

swagfag
Posts: 928
Joined: 11 Jan 2017, 17:59

### Re: Cycling keystrokes?

`cycle(start, step) { static i := 0 return Mod((++i - 1), step) + start}F7::Send % cycle(3, 3)Esc::ExitApp`
wolf_II
Posts: 1975
Joined: 08 Feb 2015, 20:55

### Re: Cycling keystrokes?

One Two more:
First with ByRef parameter:
`Current := 0F7:: Send, % Cycle(Current)Cycle(ByRef Count) { Return, Count -= (++Count > 3) ? 3 : 0}`

And, for the heck of it, one with super-global variable:
`global Count := 0F7:: Send, % Cycle()Cycle() { Return, Count -= (++Count > 3) ? 3 : 0}`
I hope that helps.
Kryu
Posts: 7
Joined: 26 Sep 2016, 13:25

### Re: Cycling keystrokes?

It's ugly as hell, but just to practice ternary operator:

`F7::Send % (c = 5) ? (c := 3) : (c = 3) ? (c := 4) : (c = 4) ? (c := 5) : (c := 3)`
swagfag
Posts: 928
Joined: 11 Jan 2017, 17:59

### Re: Cycling keystrokes?

this isnt practice, this is abuse lol
Kryu
Posts: 7
Joined: 26 Sep 2016, 13:25

### Re: Cycling keystrokes?

swagfag wrote:this isnt practice, this is abuse lol

I agree.
tgoVIPER
Posts: 12
Joined: 22 Apr 2018, 10:28

### Re: Cycling keystrokes?

Haha!
Thanks, everyone.
They all work great and I appreciate the help.
Xtra
Posts: 1181
Joined: 02 Oct 2015, 12:15

### Re: Cycling keystrokes?

Kryu wrote: but just to practice ternary operator:

`F7::Send % c := c=3 ? 4 : c=4 ? 5 : 3`
Kryu
Posts: 7
Joined: 26 Sep 2016, 13:25

### Re: Cycling keystrokes?

Xtra wrote:
Kryu wrote: but just to practice ternary operator:

`F7::Send % c := c=3 ? 4 : c=4 ? 5 : 3`

Thanks!