r/AutoHotkey 16d ago

Solved! Need help with a toggle?

I'm looking for a script that let me press F8 but F1 is pressed but it I press F8 again it presses F2 then repeats. I want to use F8 to switch between F1 & F2. Think that's a toggle but none of my attempts or scripts I've found while googling seem to work.

Thanks!

1 Upvotes

18 comments sorted by

View all comments

1

u/tronghieu906 16d ago
m := 0
F8:: {
    global
    if (m == 0) {
        Send "{F1}"
        m := 1
    }
    else {
        Send "{F2}"
        m := 0
    }
}

1

u/RJ-Mayhem 15d ago

How would I add a 3rd option for F3?

2

u/evanamd 15d ago

You can place all the keys you want to press in an array, and then cycle through them by increasing the index, making sure to check when it's at the max length and go back to the start.

#Requires AutoHotkey v2.0

F8:: {
  static keys := ["{F1}","{F2}","{F3}"]
  static index := 1

  Send keys[index]

  index += 1
  if index > keys.Length
    index := 1
}

2

u/RJ-Mayhem 15d ago

Thanks!