Page 1 of 1
How do I combine this toggle
Posted: 27 Mar 2024, 01:56
by jellopudding
Code: Select all
#Requires AutoHotkey >=2.0
#SingleInstance Force
#HotIf WinActive("ahk_exe Chrome.exe")
b::
{
static toggle := 1
toggle := !toggle
}
v::
{
If toggle
{
Loop
{
Send ("{z down}")
Sleep 30
Send ("{z up}")
If not GetKeyState("v", "P")
Break
}
else
Send "V"
}
}
Thank you
I would like for "b" to act as a toggle and for "v" to rapid press z if toggle is on, and as regular v when toggle is off.
Re: How do I combine this toggle
Posted: 27 Mar 2024, 02:36
by reddyshyam
Hi
@jellopudding
Please use Global variable instead of static.
Code: Select all
#Requires AutoHotkey >=2.0
#SingleInstance Force
#HotIf WinActive("ahk_exe Chrome.exe")
toggle := true
b::{
Global toggle := !toggle
}
v::{
if toggle {
Loop {
Send ("{z down}")
Sleep 30
Send ("{z up}")
If not GetKeyState("v", "P")
Break
}
} else
Send "V"
}
Re: How do I combine this toggle
Posted: 27 Mar 2024, 08:47
by jellopudding
Thank you. Tried global toggles a few times but couldn't figure out where to place it to make it work (and kept reading not to use it when I looked it up).
Re: How do I combine this toggle
Posted: 27 Mar 2024, 13:17
by niCode
For fun, and because I don't like globals, here's a way to do it without global variables:
Code: Select all
#Requires AutoHotkey >=2.0
#SingleInstance Force
#HotIf WinActive('ahk_exe Chrome.exe')
$b::ChromeToggle(true)
#HotIf ChromeToggle()
$v:: {
SetKeyDelay(, 30)
while GetKeyState('v', 'P') {
SendEvent('z')
}
}
#HotIf
ChromeToggle(flip := false) {
static toggle := false
flip ? toggle := !toggle : 0
return toggle and WinActive('ahk_exe Chrome.exe')
}