Key loop

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Typical-User
Posts: 11
Joined: 15 Jun 2019, 06:38

Key loop

15 Oct 2020, 08:45

Hi all

I was seraching to find a script which, when pressing a key, lets say "z" for 4 times without any time limit, then the script sends the key "k".
All searches i did with loop keyword, had no luck, and some older script i made, had the sleep command which in this case not helping at all.
Anybody can help?

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

Re: Key loop

15 Oct 2020, 09:47

Code: Select all

:?*:zzzz::k
Typical-User
Posts: 11
Joined: 15 Jun 2019, 06:38

Re: Key loop

15 Oct 2020, 11:34

Thank you. It was quite more simple than i could immagine. :P
A silly question. If in future want to convert the zzzz into mouse clicks, i have to use the getkeystate command?
User avatar
mikeyww
Posts: 26931
Joined: 09 Sep 2014, 18:38

Re: Key loop

15 Oct 2020, 12:06

Not necessarily. You can do things like:

Code: Select all

:?*:zzzz::
Click
Return
or issue any other commands there. The decision between whether to use a hotstring (as here) or a hotkey approach may relate to whether you want to trigger the code regardless of whether you are typing into a form. Hotstrings are used while typing into an edit box of some kind. Hotkeys can be used as triggers anywhere.

If you want to use a hotkey as a trigger, then yes, you would assign one key or key combination as the trigger, and the rest of the key presses would need to be detected in the subsequent code.
Typical-User
Posts: 11
Joined: 15 Jun 2019, 06:38

Re: Key loop

15 Oct 2020, 12:47

I mean, instead of the zzzz, to activate the same sequence after 4 clicks of RButton.
i tried to use Rbutton, but due to the up and down state, is not working.
User avatar
mikeyww
Posts: 26931
Joined: 09 Sep 2014, 18:38

Re: Key loop

15 Oct 2020, 13:26

RButton would need a hotkey, so you are correct: you would use RButton as the hotkey, and then look for subsequent key presses. Could look at KeyWait as a command of interest. This forum also has lots of examples of using button presses in hotkeys. Example is below.

Code: Select all

RButton::
KeyWait, RButton, D ; This button was pressed
KeyWait, RButton ; This button was released
KeyWait, RButton, D T1 ; See whether button is pressed a second time
If ErrorLevel
 MsgBox, 48, No, RButton was not pressed again.
Else MsgBox, 64, Yes, RButton was pressed again.
Return

F4::
SoundBeep, 1500, 20
ExitApp
Return
There could be other ways to do this, such as just counting the clicks and seeing if four of them fall within a certain period. The following may be of interest.

https://autohotkey.com/board/topic/35566-rapidhotkey/

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Dobbythenerd1 and 300 guests