Page 1 of 1
Loop sticking with "P"
Posted: 18 Jan 2022, 14:50
by SarahJ
I have 2 kinds of loops currently. Ive narrowed down my button sticking in NW to those with Getkeystate("key" "P") and those without the "P". Problem is that only some of my keys will work without the "P". My left button on moue and my spacebar wont work without it so they stick all the time. Is there a way to get these keys to stop sticking or work without the "P"? Ive tried every loop type people have suggested already.
sample code:
Code: Select all
space::
while GetKeyState("space", "P")
{
send {space}
sleep 200
}
return
Code: Select all
1::
gosub, one
return
one:
if getkeystate("1")
{
send 1
settimer, one, -200
}
return
Re: Loop sticking with "P"
Posted: 18 Jan 2022, 15:13
by mikeyww
If you send the same key as the hotkey, prefix the hotkey with
a dollar sign to prevent the loop. Various flavors are below.
Code: Select all
$Space::
SetKeyDelay, 200
Send {Space}
Return
Code: Select all
#UseHook
Space::
1::
SetKeyDelay, 200
Send {%A_ThisHotkey%}
Return
#UseHook Off
Code: Select all
SetKeyDelay, 200
#UseHook
Space::
1::Send {%A_ThisHotkey%}
#UseHook Off
Code: Select all
SetKeyDelay, 200
$Space::
$1::Send % "{" SubStr(A_ThisHotkey, 2) "}"
Sleep is also OK.
Code: Select all
$Space::
Send {Space}
Sleep, 190
Return
Re: Loop sticking with "P"
Posted: 20 Jan 2022, 03:41
by SarahJ
its supposed to loop while the key is held down. But the loop keeps going sometimes when I let up on the key. In KeyHistory it shows the key down the whole time. This only applies to GetKeyState loops with the "P" setting though.
Re: Loop sticking with "P"
Posted: 20 Jan 2022, 04:57
by mikeyww
You can post your revised script here. Please note my comment about the dollar prefix, which applies the hook. I included a citation to an explanation of it. It would also be useful to know whether you tried any of the scripts that I posted, and whether they work.
Here is an example that you can adapt.
viewtopic.php?p=439864#p439864 You can remove the
+ if you do not need to use
Shift.
Re: Loop sticking with "P"
Posted: 20 Jan 2022, 07:20
by Rohwedder
Hallo,
perhaps?:
Code: Select all
Global Repeat := []
$Space::Repeat(200)
$1::Repeat(200)
Repeat(Time:=30) {
RegExMatch(A_ThisHotkey, "\W$|\w*$", Key)
IF !Repeat[Key] {
Repeat[Key] := True
Timer := Func("Timer").Bind([Key,-Max(Abs(Time),1)])
SetTimer,% Timer,% -10
}}
Timer(B) {
IF Repeat[B.1] := GetKeyState(B.1, "P") {
SendInput,% "{Blind}{" B.1 "}"
Timer := Func("Timer").Bind(B)
SetTimer,% Timer,% B.2
}}
Re: Loop sticking with "P"
Posted: 21 Jan 2022, 00:07
by SarahJ
I had read through the link and im pretty sure Im using the hook in the entire script. I will try adding the dollar sign and using setkeydelay. Trying the space bar one to see if it sticks and ill replace all my buttons if it doesnt. My mouse unfortunately is one of the ones that sticks. And from what I understand the mouse always uses the hook. These are in the script.
#InstallKeybdHook
#InstallMouseHook
Re: Loop sticking with "P"
Posted: 21 Jan 2022, 00:59
by Xtra
You don't need to use
GetKeyState().
Example:
Code: Select all
$space::
running := 1
Loop
{
Send, {space}
Sleep 200
}until !running
return
$space up::running := 0
Re: Loop sticking with "P"
Posted: 21 Jan 2022, 21:30
by SarahJ
ah ill try this with the Key up thanks