Initiate Counter With Multiple Keys

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
drfire
Posts: 1
Joined: 28 Nov 2015, 17:51

Initiate Counter With Multiple Keys

28 Nov 2015, 18:00

Hello.

I basically have this script, which I use for a game:

Code: Select all

i:=!i ; initiate counter
a::
if ( i = 1 ) {
  Click Right
  i++ ; count increment
}
else if ( i = 2 ) {
  Mousemove,0,70,0,R
  i++ ; count increment
}
else if ( i = 3 ) {
Click
Random, rand, 50, 150
Sleep % rand
Mousemove,0,-70,0,R
  i:=!!i ; initiate counter
I want the counter to be triggered by "a", "s" and "d". So if I press all 3 buttons at the same time the whole script gets executed and it doesn't matter which button I press first. How do I do this? (I know it would work, but I don't want to press 1 button for all actions.)
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Initiate Counter With Multiple Keys

29 Nov 2015, 16:13

Do you want to make a script where a, s, OR d start up that code? It would be like this:

Code: Select all

a::
s::
d::
If ( i = 1 ) {
; rest of code
But, you're saying to do a, s, AND d, yeah? That's a bit trickier, but you can try this:

Code: Select all

#If GetKeyState ("a","p")
s & d::
If ( i = 1 ) {
; rest of code
But the problem is that requires a to be pressed first (or maybe pressing s, then a, then d works). s & d there are a custom hotkey.

For the order to not matter, this should work, however... it might trigger multiple threads, I'm not so sure.

Code: Select all

a::
s::
d::
KeyWait, a, d
KeyWait, s, d
KeyWait, d, d ; the d in all three mean "Down"
If !GetKeyState("a","p") || !GetKeyState("s","p") || !GetKeyState("d","p")
return ; all three keys are not currently held down
; rest of code
The ! is the logical-not operator. The || is the OR operator.

But, thinking it over, it should be viable to do the above with only a single a:: hotkey (remove s:: and d::), as if you press a last, it will still active the hotkey and the KeyWaits will be satisfied.

You may find some trouble using KeyWait if there is no TimeOut parameter, so consider adding one. An example of a 2 second timeout is this: KeyWait, a, d T2.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], haomingchen1998 and 141 guests