Need help in toggling

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
zenoriellz
Posts: 6
Joined: 27 Nov 2021, 08:33

Need help in toggling

27 Nov 2021, 09:16

can someone please help me with this concept, Im still struggling, ignorant and still learning more about this ahk, I searched but not getting the result i want to, really need some help

example:
i want this macro which is A B C D under the z hotkey to be toggle but the catch is when i press the toggle key again which is Z the result will not complete the whole macro which is A B C D but instead it will give me the result prior to how long i waited for the z hotkey to be pressed again, for example i pressed the z hotkey and wait for 200 millisecond so the macro command will give me the A B only as a result not the A B C D

Code: Select all

z::

send A
sleep 100

send B
sleep 100

send C
sleep 100

send D
sleep 100
[Mod edit: [code][/code] tags added.]
User avatar
mikeyww
Posts: 26849
Joined: 09 Sep 2014, 18:38

Re: Need help in toggling

27 Nov 2021, 10:09

Welcome to AHK!

Code: Select all

#MaxThreadsPerHotkey 2
z::
SetKeyDelay, 100
on := !on
Loop, Parse, % "abcd"
 Send % on ? A_LoopField : ""
on := False
Return
zenoriellz
Posts: 6
Joined: 27 Nov 2021, 08:33

Re: Need help in toggling

27 Nov 2021, 10:20

mikeyww wrote:
27 Nov 2021, 10:09
Welcome to AHK!

Code: Select all

#MaxThreadsPerHotkey 2
z::
SetKeyDelay, 100
on := !on
Loop, Parse, % "abcd"
 Send % on ? A_LoopField : ""
on := False
Return
literally wow , im researching about this concept for so long but for you its like chewing a gum in the park, thanks a lot . I really aprreciated your fast response. though i dont really understand the commands each line, one more request sir, for me to understand fully the script can you give me the link or source where i can review that concept behind every codes used there?
zenoriellz
Posts: 6
Joined: 27 Nov 2021, 08:33

Re: Need help in toggling

27 Nov 2021, 11:21

how about this kind of situation sir i want to input different sleep value in different command what code should i use for this one sir

Code: Select all

send {Numpad1 down}
sleep 100
send {Numpad1 up}


send {Numpad2 down}
sleep 200
send {Numpad2 up}

send {Numpad3 down}
sleep 300
send {Numpad3 up}
[Mod edit: [code][/code] tags added.]
User avatar
mikeyww
Posts: 26849
Joined: 09 Sep 2014, 18:38

Re: Need help in toggling

27 Nov 2021, 11:58

Code: Select all

#MaxThreadsPerHotkey 2
z::
on := !on
Loop, 3 {
 If !on
  Return
 SetKeyDelay,, 100 * A_Index
 Send {Numpad%A_Index%}
}
on := False
Return
Explained: Loop
zenoriellz
Posts: 6
Joined: 27 Nov 2021, 08:33

Re: Need help in toggling

27 Nov 2021, 15:48

ive come up with this simple macro code for personal use .my problem now is how to break that loop when the hotkey z is pressed again for a specific time so that i will not get the full loop of the script as a result . I run the script still its giving me this code "d4dds6 as4" even though i quickly pressed the z hotkey so that my goal is to get a specific code prior to time i pressed the key again.

Code: Select all

#MaxThreadsPerHotkey 2
f6::reload
f7::suspend

z::
toggle := !toggle
Loop {
    if (toggle) {
 
send {d down}	
send {Numpad4 down}	
sleep 100	
send {d up}	
send {Numpad4 up}	
send {d down}	
sleep 200
send {d up}	
sleep 300	
send {d down}
send {s down}	
send {Numpad6 down}	
sleep 100	
send {d up}	
send {s up}	
send {Numpad6 up}	
sleep 50
send {space}
sleep 50
send {a down}	
send {s down}	
send {Numpad4 down}	
sleep 50	
send {a up}	
send {s up}	
send {Numpad4 up}	


 } else {
        break
    }
}
return
[Mod edit: [code][/code] tags added.]
Last edited by gregster on 27 Nov 2021, 19:11, edited 1 time in total.
Reason: Please use code tags. Thank you!
User avatar
mikeyww
Posts: 26849
Joined: 09 Sep 2014, 18:38

Re: Need help in toggling

27 Nov 2021, 18:23

If your toggle is reset, then you can issue a Reload command.
zenoriellz
Posts: 6
Joined: 27 Nov 2021, 08:33

Re: Need help in toggling

28 Nov 2021, 09:24

mikeyww wrote:
27 Nov 2021, 18:23
If your toggle is reset, then you can issue a Reload command.

Code: Select all

thank you sir  :bravo: 

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: LepG, mapcarter, OrangeCat and 256 guests