Cycling through an array of functions...

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
zed6250jb
Posts: 54
Joined: 20 Apr 2024, 18:25
Contact:

Cycling through an array of functions...

Post by zed6250jb » 26 Apr 2024, 15:25

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

User avatar
mikeyww
Posts: 27133
Joined: 09 Sep 2014, 18:38

Re: Cycling through an array of functions...

Post by mikeyww » 26 Apr 2024, 15:57

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

Post Reply

Return to “Ask for Help (v2)”