Descolada wrote: ↑03 Jul 2022, 10:57
I've had similar issues with LButton not being released or the LButton Up hotkey not always triggering. Using SetTimers has worked so far, so perhaps this would work:
Code: Select all
SetBatchLines, -1
#IfWinActive ahk_exe notepad.exe
LButton::
Click
SetTimer, ClickRoutine, 80
While GetKeyState("LButton", "P") {
Sleep, 10
}
SetTimer, ClickRoutine, Off
Return
#IfWinActive
ClickRoutine:
Click
return
F5::ExitApp
That's the alternative method I used, still stuck sometimes
Rohwedder wrote: ↑03 Jul 2022, 11:41
Hallo,
use in Firefox your demo.html and try:
Code: Select all
SetBatchLines, -1
SetMouseDelay, -1
#InstallMouseHook
#IfWinActive ahk_exe Firefox.exe
LButton::
SetTimer, No, 100
Send, {F5} ;to reset demo.html
Sleep, 100
While, GetKeyState("LButton","P")
Click,% (,No := A_Index)
SetTimer, No, -10
MsgBox, ***LMB Released***
Return
#IfWinActive
No:
ToolTip,% No
Return
While I clicked on "Click Me", Firefox only captured about half of the clicks. The message box appeared
exactly when LButton was released. Firefox then continued counting as long as there were still clicks in the buffer.
AHK has no problems with LMB release detection, but Firefox with too large click rate.
I made a CPS.html (Clicks per Second) from your demo.html. My Firefox does not reach 400 CPS, Autohotkey exceeds 1000.
CPS.html:
Code: Select all
<!doctype html><head><title>Clicks per second</title><style>
.box{position:absolute;width:10em;}
.text{left:30%;top:5%;height:1em;overflow:hidden;
text-overflow:ellipsis;max-width:4em;}
.btn{left:30%;top:10%;width:4em;height:3em;}
.btn:active{background-color:red;}</style></head><body>
<button class="btn box" onclick=f()>Click Me</button>
<span class="text box">0</span>
<script>start=No=0;t = document.querySelector('.text');
function f(){if(!start)start=new Date;
t.textContent=++No/(new Date-start)*1000}</script></body>
Thanks for you test, then I found that
(1). The stuck problem not only happens to LMB, also applies to other button on mouse, I reproduced it with XButton1
(2). The stuck problem WON'T happen when bind key to keyboard button, for example "w" button (tested for 5 minutes)
(2.1) This difference might be related the different low-level signal handling of keyboard and mouse. When using mouse button as trigger, the trigger feels instantly, but with keyboard it feels like there's a internal delay for keypress
(3). I can't reproduce the "Firefox then continued counting as long as there were still clicks in the buffer" thing, my firefox count to 900 cps and stops when trigger key released. That might be related to cpu power or something, I do observe such "buffer click" thing in some web page games though
(4). As I said, to reproduce this bug, keep pressing LMB is not enough, you need to follow the step I wrote above:
4. Hold LMB on the button, release it after few seconds, repeat
I tweaked your code and tested it:
Demo for situation (1): stuck click after few tries, I move mouse to left edge when holding it to indicate the REAL physical state of mouse button press
- An1.gif (821.03 KiB) Viewed 1279 times
Demo for (2): no stuck when using keyboard to trigger it, similar move method
- An2.gif (384.45 KiB) Viewed 1279 times
Code for mouse demo:
Code: Select all
SetBatchLines, -1
SetMouseDelay, -1
SetKeyDelay, -1
#InstallMouseHook
#IfWinActive ahk_exe Firefox.exe
LButton::
SetTimer, No, 100
While, GetKeyState("LButton","P")
Click,% (,No := A_Index)
SetTimer, No, off
ToolTip, %No% ***LMB Released***
Return
#IfWinActive
No:
ToolTip,% No
Return
Code for keyboard demo:
Code: Select all
SetBatchLines, -1
SetMouseDelay, -1
SetKeyDelay, -1
#InstallMouseHook
#IfWinActive ahk_exe Firefox.exe
w::
SetTimer, No, 100
While, GetKeyState("w","P")
Click,% (,No := A_Index)
SetTimer, No, off
ToolTip, %No% ***w Released***
Return
#IfWinActive
No:
ToolTip,% No
Return
p.s. the count in second line is just to make sure firefox didn't missed any click, you can ignore it