same hotkey 2 macros. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
gudarks
Posts: 7
Joined: 11 Jun 2018, 21:07

same hotkey 2 macros.

Post by gudarks » 14 Jun 2021, 09:56

Hello i'm trying to make 2 macros with same hotkey.

Code: Select all

f::
breakLoop := False
While GetKeyState("f", "P"){
;MACRO1
;0
Send, {d down}
sleep 20
Send, {d up}
Sleep 20
Send, {d down} {numpad1 down}
sleep 10
Send, {d up} {numpad1 up}
sleep 20
;MACRO 2
;1
Send, {a down}
sleep 30
Send, {a up}
Sleep 80
Send, {s down}
sleep 30
Send, {d down}
sleep 40
Send, {numpad8 down}
sleep 20
Send, {s up} {a up}
sleep 20
}
Return
f Up::
breakLoop := True
Return
i would like to use another hotkey to switch macro 1 and 2 when i press F hotkey.

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

Re: same hotkey 2 macros.  Topic is solved

Post by mikeyww » 14 Jun 2021, 10:20

An example is below.

Code: Select all

#InstallKeybdHook

F3::
two := !two
SoundBeep, 1000 + 500 * two
Return

f Up::
breakLoop := True
Send {Numpad8 up}
Return

f::
breakLoop := False
While GetKeyState("f", "P") {
 Send {d down}
 Sleep, 20
 Send {d up}
 Sleep, 20
 Send {d down} {Numpad1 down}
 Sleep, 10
 Send {d up} {Numpad1 up}
}
Return

#If two
f::
While GetKeyState("f", "P") {
 Send {a down}
 Sleep, 30
 Send {a up}
 Sleep, 80
 Send {s down}
 Sleep, 30
 Send {d down}
 Sleep, 40
 Send {Numpad8 down}
 Sleep, 20
 Send {s up} {d up}
}
Return
#If
Alternatively, you could just check the variable state inside a single routine, and act accordingly.

Code: Select all

#InstallKeybdHook

F3::
two := !two
SoundBeep, 1000 + 500 * two
Return

f::
breakLoop := False
While GetKeyState("f", "P") {
 If two {
  Send {a down}
  Sleep, 30
  Send {a up}
  Sleep, 80
  Send {s down}
  Sleep, 30
  Send {d down}
  Sleep, 40
  Send {Numpad8 down}
  Sleep, 20
  Send {s up} {d up}{Numpad8 up}
 } Else {
  Send {d down}
  Sleep, 20
  Send {d up}
  Sleep, 20
  Send {d down} {Numpad1 down}
  Sleep, 10
  Send {d up} {Numpad1 up}
 }
}
breakLoop := True
Return

gudarks
Posts: 7
Joined: 11 Jun 2018, 21:07

Re: same hotkey 2 macros.

Post by gudarks » 14 Jun 2021, 18:36

mikeyww wrote:
14 Jun 2021, 10:20
An example is below.

Code: Select all

#InstallKeybdHook

F3::
two := !two
SoundBeep, 1000 + 500 * two
Return

f Up::
breakLoop := True
Send {Numpad8 up}
Return

f::
breakLoop := False
While GetKeyState("f", "P") {
 Send {d down}
 Sleep, 20
 Send {d up}
 Sleep, 20
 Send {d down} {Numpad1 down}
 Sleep, 10
 Send {d up} {Numpad1 up}
}
Return

#If two
f::
While GetKeyState("f", "P") {
 Send {a down}
 Sleep, 30
 Send {a up}
 Sleep, 80
 Send {s down}
 Sleep, 30
 Send {d down}
 Sleep, 40
 Send {Numpad8 down}
 Sleep, 20
 Send {s up} {d up}
}
Return
#If
Alternatively, you could just check the variable state inside a single routine, and act accordingly.

Code: Select all

#InstallKeybdHook

F3::
two := !two
SoundBeep, 1000 + 500 * two
Return

f::
breakLoop := False
While GetKeyState("f", "P") {
 If two {
  Send {a down}
  Sleep, 30
  Send {a up}
  Sleep, 80
  Send {s down}
  Sleep, 30
  Send {d down}
  Sleep, 40
  Send {Numpad8 down}
  Sleep, 20
  Send {s up} {d up}{Numpad8 up}
 } Else {
  Send {d down}
  Sleep, 20
  Send {d up}
  Sleep, 20
  Send {d down} {Numpad1 down}
  Sleep, 10
  Send {d up} {Numpad1 up}
 }
}
breakLoop := True
Return
Thanks it work flawlessly. Just one more question is there a way that i can use the f3 to use into various ahk script simultaneously?

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

Re: same hotkey 2 macros.

Post by mikeyww » 14 Jun 2021, 20:05

Probably, but I'm not sure what you mean by, "use the f3 to use into various ahk script".

gudarks
Posts: 7
Joined: 11 Jun 2018, 21:07

Re: same hotkey 2 macros.

Post by gudarks » 14 Jun 2021, 20:11

Example:
Script 1

Code: Select all

#InstallKeybdHook

F3::
two := !two
SoundBeep, 1000 + 500 * two
Return

numpad3::
breakLoop := False
While GetKeyState("numpad3", "P") {
 If two {
Send, {a down}
sleep 30
Send, {a up}
Sleep 80
Send, {s down}
sleep 30
Send, {a down}
sleep 40
Send, {numpad8 down}
sleep 20
Send, {s up} {a up}
sleep 20
Send, {numpad8 up}
If breakLoop
  Break
}
Else {
  Send, {d down}
sleep 30
Send, {d up}
Sleep 80
Send, {s down}
sleep 30
Send, {d down}
sleep 40
Send, {numpad8 down}
sleep 20
Send, {s up} {d up}
sleep 20
Send, {numpad8 up}
If breakLoop
  Break
 }
 }
 Return
numpad3 Up::
breakLoop := True
Return
Script 2

Code: Select all

F3::
two := !two
SoundBeep, 1000 + 500 * two
Return

ctrl::
breakLoop := False
While GetKeyState("ctrl", "P") {
 If two {
Send, {a down}
sleep 10
Send, {s down}
sleep 10
Send, {a up}
sleep 10
Send, {d down}
Sleep 10
Send, {s up}
sleep 10
Send, {s down}
Sleep 10
Send, {d up}
sleep 10
Send, {a down}
sleep 10
Send, {s up}
Send, {numpad4 down} {numpad7 down}
sleep 10
Send, {numpad4 up}
sleep 10
Send, {numpad7 up} 
sleep 10
Send, {a up}
If breakLoop
  Break
}
Else {
  Send, {d down}
sleep 10
Send, {s down}
sleep 10
Send, {d up}
sleep 10
Send, {a down}
Sleep 10
Send, {s up}
sleep 10
Send, {s down}
Sleep 10
Send, {a up}
sleep 10
Send, {d down}
sleep 10
Send, {s up}
Send, {numpad4 down} {numpad7 down}
sleep 10
Send, {numpad4 up}
sleep 10
Send, {numpad7 up} 
sleep 10
Send, {d up}}
If breakLoop
  Break
 }
 }
 Return
ctrl Up::
breakLoop := True
Return
when i press f3 the second script doesn't change. Is there a workaround this?

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

Re: same hotkey 2 macros.

Post by mikeyww » 14 Jun 2021, 20:43

Combine the scripts.

Post Reply

Return to “Ask for Help (v1)”