shortcut key for 4 options Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
omar bishr
Posts: 92
Joined: 23 Nov 2020, 23:05

shortcut key for 4 options

Post by omar bishr » 22 Jan 2023, 14:19

here what i am trying to do:
i have 4 simple scripts:

Code: Select all

z::
send {!z}
return
x::
send {!v}
return
d::
send {!d}
return
f::
send {!f}
return
what i want to do is to make this 4 scripts work with one key only (z key) first click of z key to active first script send {!z}
second click to active second script {!v}
third.........
and after last script reset to active for 1 to 4

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

Re: shortcut key for 4 options

Post by mikeyww » 22 Jan 2023, 14:44

Code: Select all

#Requires AutoHotkey v1.1.33
n := 0
z::Send % ["!z", "!v", "!d", "!f"][Mod(n++, 4) + 1]

Code: Select all

#Requires AutoHotkey v2.0
z:: {
 Static n := 0
 Send ["!z", "!v", "!d", "!f"][Mod(n++, 4) + 1]
}

omar bishr
Posts: 92
Joined: 23 Nov 2020, 23:05

Re: shortcut key for 4 options

Post by omar bishr » 22 Jan 2023, 15:24

mikeyww wrote:
22 Jan 2023, 14:44

Code: Select all

#Requires AutoHotkey v1.1.33
n := 0
z::Send % ["!z", "!v", "!d", "!f"][Mod(n++, 4) + 1]

this works for me:

Code: Select all

#Requires AutoHotkey v1.1.33
n := 0
z::Send % ["!z", "!v", "!d", "!f"][Mod(n++, 4) + 1]
but i saw i can switch !z witch is first script with {click ,300,10}
like this :

Code: Select all

#Requires AutoHotkey v1.1.33
n := 0
z::Send % [" {click ,300,10}", "!v", "!d", "!f"][Mod(n++, 4) + 1]
i want to switch !z (first click of z key) with this:
{click ,300,10}
sleep, 1600
send, !c
return

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

Re: shortcut key for 4 options

Post by mikeyww » 22 Jan 2023, 16:03

Code: Select all

#Requires AutoHotkey v1.1.33
n := 0
z::
Switch Mod(++n, 4) {
 Case 1:
  Click 300 10
  Sleep 1600
  Send !c
 Case 2:
  Send 2
 Case 3:
  Send 3
 Case 0:
  Send 4
}

omar bishr
Posts: 92
Joined: 23 Nov 2020, 23:05

Re: shortcut key for 4 options  Topic is solved

Post by omar bishr » 22 Jan 2023, 16:56

mikeyww wrote:
22 Jan 2023, 16:03

Code: Select all

#Requires AutoHotkey v1.1.33
n := 0
z::
Switch Mod(++n, 4) {
 Case 1:
  Click 300 10
  Sleep 1600
  Send !c
 Case 2:
  Send 2
 Case 3:
  Send 3
 Case 0:
  Send 4
}
yes thats what i need thx man you the best :clap:

User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: shortcut key for 4 options

Post by DuckingQuack » 27 Jan 2023, 06:34

I have spent all week trying to decipher these. The first pair had me seriously scratching my head until i read about square brackets dynamically creating arrays, but then i was stuck on the mod section and how .25, .5, .75, and 1 would cycle through the first sequence of the array or the switch without having to reach a point that it started getting remainders… then I realized that if you’re looking for a remainder, your result will never have a decimal, you get a whole number and I was wrong for even doing the math! The first round is literally 1/4=0 R1!

This is an extremely neat cyclic incrementing progression system and i fully intend to use it in my scripts!

Thank you @mikeyww for another amazing lesson learned!

mikeyww wrote:
22 Jan 2023, 14:44

Code: Select all

#Requires AutoHotkey v1.1.33
n := 0
z::Send % ["!z", "!v", "!d", "!f"][Mod(n++, 4) + 1]

#Requires AutoHotkey v2.0
z:: {
 Static n := 0
 Send ["!z", "!v", "!d", "!f"][Mod(n++, 4) + 1]
}
mikeyww wrote:
22 Jan 2023, 16:03

Code: Select all

#Requires AutoHotkey v1.1.33
n := 0
z::
Switch Mod(++n, 4) {
 Case 1:
  Click 300 10
  Sleep 1600
  Send !c
 Case 2:
  Send 2
 Case 3:
  Send 3
 Case 0:
  Send 4
}
Best of Luck,
The Duck

Post Reply

Return to “Ask for Help (v1)”