Page 1 of 1
Cycle Keys
Posted: 16 Apr 2019, 08:30
by foguetes
Hi
I am working on a script that will cycle through a list of key combos. Right now if I press Ctrl+Alt+Shift+F1 it cycles through the combos forwards. The combos are Ctrl + (numpad1-9) and the Ctrl + Shit + (numpad1-7) and then it goes back to zero which is Ctrl + numpad0.
My question is: how can I make it cycle backwards if I press Ctrl + Alt + F1 ?
Code: Select all
^!+F1::
key++ ; this will help cycling through the keys depending on its value
if key = 1
Send, ^{Numpad1}
else if key = 2
Send, ^{Numpad2}
else if key = 3
Send, ^{Numpad3}
else if key = 4
Send, ^{Numpad4}
else if key = 5
Send, ^{Numpad5}
else if key = 6
Send, ^{Numpad6}
else if key = 7
Send, ^{Numpad7}
else if key = 8
Send, ^{Numpad8}
else if key = 9
Send, ^{Numpad9}
else if key = 10
Send, ^+{Numpad1}
else if key = 11
Send, ^+{Numpad2}
else if key = 12
Send, ^+{Numpad3}
else if key = 13
Send, ^+{Numpad4}
else if key = 14
Send, ^+{Numpad5}
else if key = 15
Send, ^+{Numpad6}
else if key = 16
Send, ^+{Numpad7}
else if key = 17
{
Send, ^{Numpad0}
key = 0 ; return to the original state... do this on the last hotkey you would like to send
}
return
Re: Cycle Keys
Posted: 16 Apr 2019, 09:31
by evilC
Code: Select all
num := 0
return
F1::
num++
if (num > 16)
num := 0
DoSend(num)
return
F2::
num--
if (num < 0)
num := 16
DoSend(num)
return
DoSend(num){
pfx := "^"
key := num
if (num > 9){
pfx .= "+"
key -= 9
}
str := pfx "{Numpad" key "}"
Send % str
;~ Tooltip % str
}
Re: Cycle Keys
Posted: 16 Apr 2019, 09:58
by Rohwedder
Hallo,
try:
Code: Select all
key = 0
Return
^!+F1::
IF key++ > 16
key = 0
key2 := Mod(key,10)+(key>9)
Send, ^{Numpad%key2%}
Return
^!F1::
IF key-- < 0
key = 16
key2 := Mod(key,10)+(key>9)
Send, ^{Numpad%key2%}
Return
Re: Cycle Keys
Posted: 17 Apr 2019, 02:38
by foguetes
@Rohwedder's script works perfectly. There's a lot I still need to learn about autohotkey.
Re: Cycle Keys
Posted: 25 Apr 2019, 07:38
by foguetes
Rohwedder wrote: ↑16 Apr 2019, 09:58
Hallo,
try:
Code: Select all
key = 0
Return
^!+F1::
IF key++ > 16
key = 0
key2 := Mod(key,10)+(key>9)
Send, ^{Numpad%key2%}
Return
^!F1::
IF key-- < 0
key = 16
key2 := Mod(key,10)+(key>9)
Send, ^{Numpad%key2%}
Return
Actually I was wrong. Maybe I didn't pay enough attention. The script cycles through the first 10 key combinations but then it doesn't continue to the remaining 7.
Re: Cycle Keys
Posted: 25 Apr 2019, 11:28
by Rohwedder
Hallo,
the error was the post-increment/decrement: key++ and key--.
Now with pre-increment/decrement: ++key and --key.
Try:
Code: Select all
^!+F1::
IF ++key > 16
key = 0
key2 := Mod(key,10)+(key>9)
Send, ^{Numpad%key2%}
Return
^!F1::
IF --key < 0
key = 16
key2 := Mod(key,10)+(key>9)
Send, ^{Numpad%key2%}
Return
;key 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 0 1...
;key2 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 0 1...
Re: Cycle Keys
Posted: 02 May 2019, 03:57
by foguetes
Sorry to bother you about this, but it's still not working. I don't seem to understand how it's working. Every time I make a change the script keeps behaving the same way.
So, as a reminder, the sequence of keys should be:
^(Numpad 0-9) and then ^+(Numpad 1-7)
!+F1 Is the shortcut for increments
^!F1 Is the shortcut for decrements
Thanks!
Re: Cycle Keys
Posted: 02 May 2019, 04:21
by evilC
@Rohwedder You only ever send Ctrl + key, whereas for the second set he wants Ctrl+Shift+key
What was wrong with my version? It seems fine
Code: Select all
[15088] AHK| Sending ^{Numpad1}
[15088] AHK| Sending ^{Numpad2}
[15088] AHK| Sending ^{Numpad3}
[15088] AHK| Sending ^{Numpad4}
[15088] AHK| Sending ^{Numpad5}
[15088] AHK| Sending ^{Numpad6}
[15088] AHK| Sending ^{Numpad7}
[15088] AHK| Sending ^{Numpad8}
[15088] AHK| Sending ^{Numpad9}
[15088] AHK| Sending ^+{Numpad1}
[15088] AHK| Sending ^+{Numpad2}
[15088] AHK| Sending ^+{Numpad3}
[15088] AHK| Sending ^+{Numpad4}
[15088] AHK| Sending ^+{Numpad5}
[15088] AHK| Sending ^+{Numpad6}
[15088] AHK| Sending ^+{Numpad7}
[15088] AHK| Sending ^{Numpad0}
[15088] AHK| Sending ^{Numpad1}
Re: Cycle Keys
Posted: 02 May 2019, 07:34
by Rohwedder
Hallo,
I completely overlooked the shift.
Code: Select all
+q:: ;^!+F1::
IF ++key > 16
key = 0
key2 := Mod(key,10)+(key>9)
p := (key>9) ? "+":
Send, ^%p%{Numpad%key2%}
Return
q:: ;^!F1::
IF --key < 0
key = 16
key2 := Mod(key,10)+(key>9)
p := (key>9) ? "+":
Send, ^%p%{Numpad%key2%}
Return
But take evilC's version for safety's sake.
He apparently uses a verification tool.
Re: Cycle Keys
Posted: 02 May 2019, 10:34
by evilC
I just do OutputDebug instead of Send, and use DebugView to read the log
Re: Cycle Keys
Posted: 18 Jul 2019, 09:08
by foguetes
I was having a problem where this script didn't cycle through all the keys when NumLock was active (which is always).
So I made it turn NumLock off and on again using SetNumLockState.
Code: Select all
num := 0
return
^!+F1::
SetNumLockState, Off
num++
if (num > 16)
num := 0
DoSend(num)
SetNumLockState, On
return
^!F1::
SetNumLockState, Off
num--
if (num < 0)
num := 16
DoSend(num)
SetNumLockState, On
return
DoSend(num){
pfx := "^"
key := num
if (num > 9){
pfx .= "+"
key -= 9
}
str := pfx "{Numpad" key "}"
Send % str
;~ Tooltip % str
}