How to toggle a key?

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
boiler
Posts: 17353
Joined: 21 Dec 2014, 02:44

Re: How to toggle a key?

29 Nov 2023, 01:46

No, as I said, holding the w down doesn’t cause it to repeat, and waiting for the release of the physical key has nothing to do with it. Also as I said, you need to have it send the keystroke over and over until you toggle it off. You could do that by turning SetTimer on when toggled on and turning it off when toggled off. Similar to earlier in this thread:

Code: Select all

*$w:: {
	static toggle := False
	SetTimer () => Send('{Blind}w'), 100 * toggle := !toggle ; use lower number for faster spamming
	SoundBeep toggle ? 1500 : 500
}
plautus
Posts: 89
Joined: 20 Aug 2020, 12:24

Re: How to toggle a key?

29 Nov 2023, 04:03

i was asking for a space button clicker
plautus
Posts: 89
Joined: 20 Aug 2020, 12:24

Re: How to toggle a key?

29 Nov 2023, 05:05

repeat space button toggle
User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: How to toggle a key?

29 Nov 2023, 05:51

@prz Boiler is right, i was wrong about the quotes.
Last edited by DuckingQuack on 29 Nov 2023, 13:35, edited 2 times in total.
Best of Luck,
The Duck
User avatar
boiler
Posts: 17353
Joined: 21 Dec 2014, 02:44

Re: How to toggle a key?

29 Nov 2023, 10:01

plautus wrote: i was asking for a space button clicker
That was already provided back at this post. Your game apparently doesn’t accept the virtual keystrokes, though. My latest post was in reply to prz, who apparently want a w key clicker.
User avatar
boiler
Posts: 17353
Joined: 21 Dec 2014, 02:44

Re: How to toggle a key?

29 Nov 2023, 11:51

DuckingQuack wrote:
29 Nov 2023, 05:51
@prz Your quotes are out of place if you’re trying to send “w down”… the whole expression needs quotes around it to be included in the send and then each other part that is the expression that isn’t sent but contained within needs extra quotes to remove them… it’s complicated and you’re probably better off putting “w down” in if and “w up” in else.

I can’t test this right now, but it would be something like this:
Send("{Blind}{w " ((KeyDown := !KeyDown) ? "down" : "up") "}") ” ”
I think the two at the end are needed.
I'm not sure anything is wrong with how he structured it -- just that he needed it to send multiple keypresses instead of holding it down. But this demonstrates the result of his Send by putting it in a MsgBox instead:

Code: Select all

KeyDown := False
MsgBox("{Blind}{w " ((KeyDown := !KeyDown) ? "down" : "up") "}")
; result is: {Blind}{w down}
User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: How to toggle a key?

29 Nov 2023, 14:58

@prz
This is auto walk I use in some games:

Code: Select all

XButton1:: {
    If !GetKeyState("w", "L") {
        SendEvent("{w down}")
    } Else {
        SendEvent("{w up}")
    }
}
I have it on the extra mouse button so I can use W normally. It's true that testing in NotePad will only send one "w" but in the game, you continue to run.
Best of Luck,
The Duck
plautus
Posts: 89
Joined: 20 Aug 2020, 12:24

Re: How to toggle a key?

01 Dec 2023, 16:44

maybe the space repeater is too fast?
plautus
Posts: 89
Joined: 20 Aug 2020, 12:24

Re: How to toggle a key?

15 Dec 2023, 05:30

Code: Select all

clik := () => Click()
Lalt::
+Lalt::
RCtrl::
+RCtrl:: {
 Static on := False
 If on := !on
      SetTimer(clik, 50), clik()
 Else SetTimer(clik, 0)
 KeyWait 'Ctrl'
 Send '{Ctrl up}{Shift up}'
}
Im also trying to make left + right click click simulatnously. DO i add right cliuck to the top line?

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Bing [Bot], mikeyww and 38 guests