Jump to content

Prevent too fast clicks


Recommended Posts

Does anyone have a script that prevents (double) clicks if they are too fast? So for example when you drag an item and the faulty mouse sends a (double) click event (which is usually much faster than a human click/doubleclick), this super fast  click gets ignored and the prior state (mouse button pressed) gets maintained. Only real human clicks should register as such.

Link to comment
Share on other sites

  • Moderators

sunToxx,

Welcome to the AutoIt forums.

Why not just buy a new mouse - they are pretty cheap in Germany:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

You can set the speed Windows detects a double click W10: Mauseinstellungen > Weitere Mausoptionen)

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Thanks. Throw away a 100€ mouse cause of double clicks? Not the best idea imho ;)

Also, how does the windows option differentiate between human clicks and erroneous clicks? The script is supposed to intercept too fast clicks. Why would you suggest the windows mouse options for that?

Now lets try to stay on topic please ;)

Link to comment
Share on other sites

This might be a good starting point for an AutoIt script:

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

1 hour ago, sunToxx said:

Throw away a 100€ mouse cause of double clicks? Not the best idea imho

Right!  So just repair it by replacing the offending switch(es).

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

I would replace the mouse.
What makes you sure that your mouse still works tomorrow? Today it does double-clicks, tomorrow it could be dead 😒

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

4 hours ago, sunToxx said:

Thanks. Throw away a 100€ mouse cause of double clicks? Not the best idea imho

Spend hours researching, writing and debugging a one-off mouse script?

How many hours of work does it take you to earn 100 Euros?

Code hard, but don’t hard code...

Link to comment
Share on other sites

On 4/15/2021 at 12:54 PM, Nine said:

You could use a low-level mouse callback to intercept clicks and decide by a simple timer if the clicks are normal or abnormal.  See this :

https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/ms644986(v=vs.85)

Thanks for that, but unfortunately my knowledge of Autoit is rather basic, mainly used it for relatively simple macros and some color recognition by now. Doing some research i found this script, which is supposed to achieve something similar, but its for AHK though, which I do not use. Considering that both programs are distant relatives, it should be possible to translate it to Autoit, I hope. Or maybe it even works like this. Will test tonight.

The script i need basically only has to add a little "deinterpolation time" to the "left mouse button up" function, in which it checks that the mouse up button is not followed by another mouse down event, within a certain timespan. You think this will do?

LButton::
sleep 20
if (GetKeyState("LButton", "P")) {
  sendinput {Blind}{LButton down} 
} else {
}
return


LButton up::
sleep 20
if (!GetKeyState("LButton", "P"))
{
  sendinput {Blind}{LButton up}
}
return

 

It's supposedly an improvement over this approach, which is said to ignore shift/ctrl -presses, which for me should also be "unbounced"
LButton::
If (A_TimeSincePriorHotkey < 100) ;hyperclick
Return
sendinput {LButton down}
KeyWait, LButton
sendinput {LButton up}
Return

 

Edited by sunToxx
Link to comment
Share on other sites

Alright, I'll give you a hand on this :

#include <WinAPIConstants.au3>
#include <WinAPISys.au3>
#include <WindowsConstants.au3>

Opt("MustDeclareVars", True)

HotKeySet("!{ESC}", _Exit) ; Alt-Esc

Global $hMouseProc, $hMouseHook
OnAutoItExitRegister(_Cleanup)

_Main()

Func _Main()
  $hMouseProc = DllCallbackRegister(_MouseProc, "long", "int;wparam;lparam")
  $hMouseHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hMouseProc), _WinAPI_GetModuleHandle(0))
  While True
    Sleep(30)
  WEnd
EndFunc   ;==>_Main

Func _MouseProc($nCode, $wParam, $lParam)
  Local Static $hTimerLeft
  Local $bFault
  If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hMouseHook, $nCode, $wParam, $lParam)
  Switch $wParam
    Case $WM_LBUTTONDOWN
      If Not $hTimerLeft Then
        $hTimerLeft = TimerInit()
      Else
        $bFault = TimerDiff($hTimerLeft) < 100 ; <<-<-<-<-<-<-<-<-<-<-<-<-<- pick the speep you want here
        $hTimerLeft = Null
        If $bFault Then Return 1 ; blocking
      EndIf
    Case $WM_RBUTTONDOWN
      ; complete this section if needed
  EndSwitch
  Return _WinAPI_CallNextHookEx($hMouseHook, $nCode, $wParam, $lParam)
EndFunc   ;==>_MouseProc

Func _Cleanup()
  _WinAPI_UnhookWindowsHookEx($hMouseHook)
  DllCallbackFree($hMouseProc)
EndFunc   ;==>_Cleanup

Func _Exit()
  Exit
EndFunc   ;==>_Exit

 

Edited by Nine
Link to comment
Share on other sites

Wow, that was some fast coding, thanks for that. It does seem to lower the amount of unintentional double clicks, although i can not say for sure yet, as the problem is rather inconsistent. So I have to verify that more longterm.

I do not realy understand what you did there. I assume the script hooks into the mouse driver and interacts directly with it. LMB down then starts a timer and if the timespan till next LMB down press is smaller than 100ms, then it is a $bFault which calls for a Return 1, which somehow cancels the unintentional doubleclick. As it seems to only account for LMB down, i do not realy understand how it manages to prevent the unintentional LMB up, which had to come prior to the next LMB down. I assume this gets injected into the normal mouse behaviour and the $bFault interupts the normal flow of things, and prevents the LMB down as well as the unintentional LMB up that came before. But will that also work for example when dragging something from one window to another? (the problem that causes the unintentional double click can also interfere with a constantly pressed LMB, making you drop things you are currently moving around with your mouse while keeping LMB pressed)

What is the advantage of doing this on a that low level within windows/driver environment? I am asking because this script seems to interfere with the mouse sensitivity. It remains normal on desktop, but is severly changed in full screen applications. The sensitivity drops massively then.

Could maybe a more basic approach also have the desired result, without doing anyting on the driver level and therefore without the resulting impact on mouse sensitivity? I was thinking like a simple macro, for example as if binding the button M to the left mouse button. Except that the macro simulates not M, but simulates the left mouse button itself. With the condition that the left button up command gets ignored if it is followed by another left button down command within x milliseconds. I think that would maybe do the trick, as long as the time limit is set short enough not to end up with a sticky LMB.

Link to comment
Share on other sites

24 minutes ago, sunToxx said:

how it manages to prevent the unintentional LMB up

I believe it is useless to prevent up, that is why I did not manage it.  But you are free to apply the same approach if need be.

26 minutes ago, sunToxx said:

unintentional double click can also interfere with a constantly pressed LMB

No, only down once.  It is not like a keyboard that repeats on holding down

27 minutes ago, sunToxx said:

It remains normal on desktop, but is severly changed in full screen applications

Yes, some applications (like full screen games) manage the mouse in their own way, so it may interfere all together.

As for another way to program this, I will let you experiment different alternatives.

But like others told you before, the best approach to your problem is to have a decent working mouse device...

Good luck.

Link to comment
Share on other sites

51 minutes ago, sunToxx said:

I am asking because this script seems to interfere with the mouse sensitivity. It remains normal on desktop, but is severly changed in full screen applications

Which “full screen applications” are you speaking of?

Could you just pause the script when using on of these apps?

Or are these “full screen applications” actually the primary target for the script and it’s mouse event manipulation magic?

Code hard, but don’t hard code...

Link to comment
Share on other sites

3 minutes ago, JockoDundee said:

Which “full screen applications” are you speaking of?

Could you just pause the script when using on of these apps?

Or are these “full screen applications” actually the primary target for the script and it’s mouse event manipulation magic?

Arr come on, why dont you just say "GAME", if the poor guy is trying to prevent his doubleclicking mouse from throwing 2 handgrenades instead of one, it hasnt got anything to do with game automation og botting. :rolleyes:

 

I myself have 2 mice laying in my drawer that does the same.

Some guy's script + some other guy's script = my script!

Link to comment
Share on other sites

Link to comment
Share on other sites

18 minutes ago, Nine said:

No, only down once.  It is not like a keyboard that repeats on holding down

That is correct, but the mouse button that you keep pressed seemingly gets the same sort of unintentional trigger while keeping it pressed, making it drop things you want to drag. I believe that makes it crucial to look at the time span between LMB up and down.

I wont ever buy another razer mouse, but at the moment it is the only available option. I do not realy care that almost all of my razer mice in the past 15 years have died shortly after warranty. But the mouse that failed now is already the replacement mouse they sent me, cause this time it failed within warranty for the first time. I was well aware razer has mediochre quality at premium prize. Unacceptable though is, that their support is very bad on top. So never another razer mouse. The only other viable option for this type of mouse (15+ button mouse) is corsair, but they are sold out till at least june in my place.

Still kind of funny how many people here give the advice to buy a new mouse, as if someone posting here has not already considered that. Still, thanks for being the only one trying to help and not going offtopic from the beginning on. I will try to figure out how to get a macro working, that simply disallows a LMB up, x milliseconds before another LMB down event. Any hints are welcome!

Link to comment
Share on other sites

6 minutes ago, Werty said:

Arr come on, why dont you just say "GAME", if the poor guy is trying to prevent his doubleclicking mouse from throwing 2 handgrenades instead of one, it hasnt got anything to do with game automation og botting. :rolleyes:

 

I myself have 2 mice laying in my drawer that does the same.

 The double click problem is obviously not limited to certain applications, it bothers everywhere. So of course a script that works as temporary workaround needs to work everywhere. I also have more mice like that. Almost all my mice died due to double clicking.

Edited by sunToxx
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...