Page 1 of 1

Cycling through an array of functions...

Posted: 26 Apr 2024, 15:25
by zed6250jb
Good evening,

I'm curious what format would a hot key would take in order to change it's effect with three single presses of buttons.

For example, the way flip phone's used to text. You would press the number 1 once to get 'a', two or three within a time limit to type 'b' or 'c' respectively before timeout and reset back to the original function or to press another number to get another possible three characters such as hitting the number 2 to get d, e or f. You know old-school texting.

I have an idea but not sure it can work as ahk complains about a missing array of values which are clearly listed below. Shown as follows.

Code: Select all

#Requires AutoHotkey v2.0

; Define your array of values
myArray := ["a", "b", "c"]
myArray2 := ["d", "e", "f"]
myArray3 := ["g", "h", "i"]

; Initialize the index
index := 0

; Define a hotkey (you can customize this)
#HotIf
1:: ; Pressing the '1' key
    { myArray[index]
    index := (index + 1) myArray.Length() ; Cycle through the array
	}
#HotIf

#HotIf
2:: ; Pressing the '2' key
    {  myArray2[index]
    index := (index + 1) myArray2.Length() ; Cycle through the array]
	}
#HotIf

#HotIf
3:: ; Pressing the '3' key
    {  myArray3[index]
    index := (index + 1) myArray3.Length() ; Cycle through the array
	}
#HotIf

Re: Cycling through an array of functions...

Posted: 26 Apr 2024, 15:57
by mikeyww
Hello,

Detect single, double, and triple-presses of a hotkey

If you want to preserve the value of a local variable from one function call to the next, you will probably want to use a static variable.

Cycling through an array