@boiler
Well, you see how everything turned out, the almost rhetorical Sunday conversation turned out to be not so useless
PS. We were taught binary mathematics back in school, in the late 80s, in computer science classes. So I've known this for a very, very long time.
How to toggle a key?
Re: How to toggle a key?
Please post your script code inside [code] ... [/code] block. Thank you.
Re: How to toggle a key?
Code: Select all
!3::
{
Static toggle := 0
Send( "{" ( toggle := !toggle ? "Space down" : "Space up" ) "}" ) ; which means {Space down} or {Space up}, depends on toggle value
SoundBeep(1500)
}
what i want is a infinite click space button loop. That can be toggled on and off.
thx so far
- DuckingQuack
- Posts: 222
- Joined: 20 Jan 2023, 18:20
Re: How to toggle a key?
@plautus
So you want a single toggle that when activated will send left click and then space in an infinite loop?
So you want a single toggle that when activated will send left click and then space in an infinite loop?
Code: Select all
#Requires AutoHotkey v2.0
#SingleInstance Force
InstallMouseHook
InstallKeybdHook
Esc::ExitApp
F1:: {
Static Toggle := False
SetTimer(FnMain, 10 * Toggle := !Toggle)
}
FnMain(){
Click
Send("{Space}")
Sleep(100)
}
Best of Luck,
The Duck
The Duck
Re: How to toggle a key?
It seems like no one here except you understands what click space button means
Please post your script code inside [code] ... [/code] block. Thank you.
Re: How to toggle a key?
I believe The Duck’s code is what is desired if the Click line is removed and the hotkey is changed to !3, but I find using Alt with spam scripts is problematic, so I would also use a single key like F1 I believe what is wanted is simply to spam the space bar with it being toggled on and off with a hotkey. Although there is no need to use Sleep since the timer is being used. And to simplify that, an anonymous fat arrow function can be used:
Code: Select all
#Requires AutoHotkey v2.0
#SingleInstance Force
Esc::ExitApp
F1:: {
Static Toggle := False
SetTimer () => Send('{Space}'), 100 * Toggle := !Toggle ; use lower number for faster spamming
}
- DuckingQuack
- Posts: 222
- Joined: 20 Jan 2023, 18:20
Re: How to toggle a key?
@boiler
Thanks! My intention was giving Plautus something simple and easily adapted. I see now I misread the requested key press, but when I read it, I was uncertain, which is why I described what that code would do.
Thanks! My intention was giving Plautus something simple and easily adapted. I see now I misread the requested key press, but when I read it, I was uncertain, which is why I described what that code would do.
Best of Luck,
The Duck
The Duck
Re: How to toggle a key?
Sure. It’s not a typical way of stating the key press, so that was just my interpretation, but it does seem to likely be what was meant.
Re: How to toggle a key?
I want a space button repeater
Re: How to toggle a key?
Did you try my script?
Re: How to toggle a key?
That’s not true. Test it in Notepad. Press F1 and it will spam spaces until you press F1 again.
Re: How to toggle a key?
2 pages... All this looks like very thick trolling.
Please post your script code inside [code] ... [/code] block. Thank you.
Re: How to toggle a key?
it works, but in game it doesnt
Re: How to toggle a key?
I was trying to make a version of this to toggle shift (for running in many games) and was having some issues before I discovered "Blind mode" https://www.autohotkey.com/docs/v2/lib/Send.htm#Blind, which attempts to unset/restore the currently pressed modifiers while your Send is running.
In my case, I able to turn LShift into a toggle using the following script
In my case, I able to turn LShift into a toggle using the following script
Code: Select all
LShift::
{
static toggle := 0
Send("{Blind}{LShift " ((toggle := !toggle) ? "down" : "up") "}")
}
Re: How to toggle a key?
I was trying to make a W key toggle, and no matter what I do I can't seem to get it to behave correctly.
I tried (with and without {Blind}) all of the following w, W, ASC 119
And, based on key history, https://www.autohotkey.com/docs/v2/lib/KeyHistory.htm vk57, sc011, vk57sc011
The closest I could get is {W down} would send a capital W, but doesn't hold the key down, and ASC 119 sends a lowercase w but again does not hold it down.
Ideally I'd like this toggle to not affect other keys that are being held down (e.g. if A or LShift etc. are being held down (or not) keep them that way, if other keys are subsequently pressed/released, keep W in whatever state was set). Any idea how to go about this?
Code: Select all
w::
{
static toggle := 0
Send("{Blind}{w " (toggle := !toggle) ? "down" : "up" "}")
}
And, based on key history, https://www.autohotkey.com/docs/v2/lib/KeyHistory.htm vk57, sc011, vk57sc011
The closest I could get is {W down} would send a capital W, but doesn't hold the key down, and ASC 119 sends a lowercase w but again does not hold it down.
Ideally I'd like this toggle to not affect other keys that are being held down (e.g. if A or LShift etc. are being held down (or not) keep them that way, if other keys are subsequently pressed/released, keep W in whatever state was set). Any idea how to go about this?
Re: How to toggle a key?
If you’re sending the same key as the hotkey (w in this case), you need to precede the hotkey label with a $ so that the hotkey doesn’t trigger itself:
Code: Select all
$w::
Re: How to toggle a key?
Hmm, I tried adding the $ but it still doesn't seem to be working for me. I also added some "debugging beeps" and it doesn't seem to be triggering itself when the $ isn't present. The behavior is the same with and without (I hear a higher pitched beep pressing W once and a lower pitched beep pressing it again, but the key still isn't being held down.)boiler wrote: ↑28 Nov 2023, 02:10If you’re sending the same key as the hotkey (w in this case), you need to precede the hotkey label with a $ so that the hotkey doesn’t trigger itself:Code: Select all
$w::
Code: Select all
w::
{
static toggle := 0
Send("{Blind}{w " ( (toggle := !toggle) ? "down" : "up") "}")
if (toggle)
SoundBeep 1500
else
SoundBeep 500
}
Re: How to toggle a key?
Did you test it in Notepad? What did it do? By the way, holding the w will not cause it to auto-repeat like when you physically hold it down. If you want it to do that, then you need to have it send the keystroke over and over until you toggle it off.
Put *$ in front of the hotkey instead of just $. The * is the wildcard prefix. See Hotkey Modifier Symbols.
Re: How to toggle a key?
Aha! * did seem to fix the detection, however it still doesn't seem to make the key repeat. I also tried adding a KeyWait to see if maybe the physical key release was causing issues, but still not working.boiler wrote: ↑28 Nov 2023, 19:32Put *$ in front of the hotkey instead of just $. The * is the wildcard prefix. See Hotkey Modifier Symbols.
Code: Select all
*$w::
{
static KeyDown := 0
;KeyWait "w"
Send("{Blind}{w " ((KeyDown := !KeyDown) ? "down" : "up") "}")
if(KeyDown)
SoundBeep 1500
else
SoundBeep 500
}