Hi, I'm trying to figure out how to set up autohotkey to cycle between keys for each keypress.
For example if I press "1" it will use 1, if I press "1" again it will use 2, if I press "1" again it will use 3.
I do not want this to be automated, I want to manually cycle between keys with each press.
Any ideas?
cycling between keys
Re: cycling between keys
This is a more basic approach, so it's longer code. Others might suggest to you to use arrays, which can be shorter.
$ modifier, variables
But in this particular use case, you could consider sending the variable itself:
Code: Select all
$1:: ; the $ prevents recursion
counter++ ; counter is a custom variable
If counter=1
Send 1
If counter=2
Send 2
If counter=3
Send 3
return
But in this particular use case, you could consider sending the variable itself:
Code: Select all
$1::
counter++
Send %counter%
return
Re: cycling between keys
I actually want it to reset to 1 after 9.
Currently it stops at 3 with the first one you listed, or it goes to infinity with the second one you listed.
Currently it stops at 3 with the first one you listed, or it goes to infinity with the second one you listed.
Re: cycling between keys
Yep, you can reset it. I'll let you modify that part. The first of course only goes to three because I only gave options for it to do an action up through 3. You're free to give it options up through 9. As for resetting it, you can assign counter a new value by using the := (or =) operator. counter:=0. (Follow that link and read the differences between := and = if you're curious, as there is a difference.)
Re: cycling between keys
Sorry, I'm having a difficult time understanding where counter:= is supposed to go in order to reset it.
Forgive me I'm new to this.
Forgive me I'm new to this.
Re: cycling between keys
":=" seems to override the rest of the scipt and just send whatever the value attached to it is and = will just add more numbers to the counter.
I think you might be thinking I want the script to run up to a defined number of sends and then stop but I want it to infintitly repeat 1-9.
I think you might be thinking I want the script to run up to a defined number of sends and then stop but I want it to infintitly repeat 1-9.
Re: cycling between keys
":=" seems to override the rest of the scipt and just send whatever the value attached to it is and = will just add more numbers to the counter.
I think you might be thinking I want the script to run up to a defined number of sends and then stop but I want it to infintitly repeat 1-9.
I think you might be thinking I want the script to run up to a defined number of sends and then stop but I want it to infintitly repeat 1-9.
Re: cycling between keys
Is there some way to make it reset after hitting return?
I've spent the last couple hours trying to figure out a solution but I can't seem to find anything that works.
I've spent the last couple hours trying to figure out a solution but I can't seem to find anything that works.
Re: cycling between keys
I found a thread from 2009 that said this should work
$1::
if count >= 9
count=0
counter++
If counter=1
Send 1
If counter=2
Send 2
If counter=3
Send 3
If counter=4
Send 4
If counter=5
Send 5
If counter=6
Send 6
If counter=7
Send 7
If counter=8
Send 8
If counter=9
Send 9
return
but it still stops counting at 9.
$1::
if count >= 9
count=0
counter++
If counter=1
Send 1
If counter=2
Send 2
If counter=3
Send 3
If counter=4
Send 4
If counter=5
Send 5
If counter=6
Send 6
If counter=7
Send 7
If counter=8
Send 8
If counter=9
Send 9
return
but it still stops counting at 9.
Re: cycling between keys
Code: Select all
count:=0,Array:=["1","2","3","4","5","6","7","8","9"]
$1::Send % Array[(++count > 9) ? count:=1 : count]
Re: cycling between keys
Thank you I love you!
Re: cycling between keys
For your attempt just before HotKeyIt's post, notice there are two variables used - count and counter. Making them all one variable should have made it work.
My intention would have been something like this:
My intention would have been something like this:
Code: Select all
$1::
counter++
Send %counter%
If counter=9
counter:=0
return
-
- Posts: 52
- Joined: 07 Nov 2015, 22:50
Re: cycling between keys
Alternatively:
Code: Select all
$1::
send, % mod(counter++, 10 )
return
Who is online
Users browsing this forum: Google [Bot], Xaucy and 162 guests