fix for a faulty mouse

Get help with using AutoHotkey and its commands and hotkeys
mkdabra
Posts: 8
Joined: 13 Nov 2015, 11:36

fix for a faulty mouse

13 Nov 2015, 12:09

I have a common enough problem: the left click on my mouse it's not on it's prime. Sometimes seems to lose contact for a fraction of a second when pressing, concluding on a doble click when pressing it just once, AND interrumpting a hold action (select text, move around icons, rotate camera in games).

I found a nice script here: http://autohotkey.com/board/topic/82509 ... /?p=524864

I'm not completely sure, as I just knew about AutoHotKey, but I think the rationale behind that script was to block a second click in too-fast succession. If so, it works nicely to prevent a single click working as a double, but that shouldn't help with button hold being interrupted. If the script does that too I'd be too glad to care being wrong :dance:

Anyway, I thought of a "logic" for a script, but I've been trying with the tutorial/help to no avail. I'm green as summer's grass. So I'll share the idea and hope someone can translate that into a working script. Pretty please.
So, here we go.

When detecting a left mouse button release, do not release
wait a given threshold (100ms for instance)
if left mouse button pressed under that threshold, do nothing
if the button is not pressed again, release

Basically the goal is for the hold to not be interrupted, for releases to be ignored if rapidly followed by a click. Something along those lines should fix the behaviour of my mouse.

I hope that can be done. Thanks for reading, and excuse the broken english.
User avatar
Exaskryz
Posts: 2876
Joined: 17 Oct 2015, 20:28

Re: fix for a faulty mouse

13 Nov 2015, 17:33

I think the KeyWait command can be used. But I'll want to include it in a loop myself just in case your mouse releases multiple times during a drag:

Code: Select all

LButton::
Click down
Loop
{
KeyWait, LButton ; waits for the release
KeyWait, LButton, D T0.2 ; waits 200 milliseconds or 0.2 seconds for you to press LButton again
If ErrorLevel ; ErrorLevel is 1 if it times out. If the LButton was not pressed again, you likely purposefully released it
   Break ; exits the loop
; If you did press the LButton again, it goes back to the first KeyWait command and waits for another release
}
Click up
return
You can play with the T parameter in the second KeyWait to figure out exactly what value works best for you. You don't want it too low or else it may not catch every accidental release (due to mouse hardware failure), but if it's too high it might get annoying waiting so long for the click up (mouse release) to be processed.
mkdabra
Posts: 8
Joined: 13 Nov 2015, 11:36

Re: fix for a faulty mouse

13 Nov 2015, 18:59

For some reason it won't execute :C
User avatar
Exaskryz
Posts: 2876
Joined: 17 Oct 2015, 20:28

Re: fix for a faulty mouse

13 Nov 2015, 19:28

Does this work?

Code: Select all

~RButton::Tooltip, You right clicked
I want to figure out what you mean by it won't execute. I just tested the code I gave and it seems to work for me.
mkdabra
Posts: 8
Joined: 13 Nov 2015, 11:36

Re: fix for a faulty mouse

13 Nov 2015, 21:04

Oh my, sorry. I just copied what was visible on the code box into the script, didn't notice I had to scroll down for the return. Important part, uh? :facepalm:

It sure has some effect, I can feel the delay. I'll tweak the threshold to just-about-enough for performance and see how it goes.

Thanks!
User avatar
MasterFocus
Posts: 146
Joined: 01 Oct 2013, 09:47
GitHub: MasterFocus
Location: Rio de Janeiro - RJ - Brasil
Contact:

Re: fix for a faulty mouse

14 Nov 2015, 00:24

Don't forget the $ modifier, or you may end up with some problems.
Read more about it here: https://www.autohotkey.com/docs/Hotkeys.htm#Symbols
Antonio França - git.io | github.com | ahk4.net | sites.google.com
Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.
Need help? Please post on the forum before sending me a PM.
mkdabra
Posts: 8
Joined: 13 Nov 2015, 11:36

Re: fix for a faulty mouse

14 Nov 2015, 11:38

"The $ prefix has no effect for mouse hotkeys, since they always use the mouse hook."

Which is a good thing, since I have no idea what a mouse hook is or where should I go insert the $ modifier :lol:
mkdabra
Posts: 8
Joined: 13 Nov 2015, 11:36

Re: fix for a faulty mouse

14 Nov 2015, 13:51

Reporting again! I've been shamelessly leeching from that other script I linked before to add some tray icon customization, as well as tampering with the timing. It looks like this now.

Code: Select all

Menu Tray, Icon, %A_WinDir%\System32\main.cpl  ; Set icon.
Menu Tray, NoStandard
Menu Tray, Add, Exit, TrayExit
Menu Tray, Tip, Delayed Release

LButton::
Click down
Loop
{
KeyWait, LButton ; waits for the release
KeyWait, LButton, D T0.06 ; waits T seconds for you to press LButton again
If ErrorLevel ; ErrorLevel is 1 if it times out. If the LButton was not pressed again, you likely purposefully released it
   Break ; exits the loop
; If you did press the LButton again, it goes back to the first KeyWait command and waits for another release
}
Click up
return

TrayExit:
ExitApp
For convenience I'd like to have a compiled version with which I could still tweak the threshold, in order to use it on "standalone mode" so to speak. Reading the other script and the tutorial I figured how to put the Menu Tray option for it, and open an Input Box and all that, but I have no idea how should I proceed to replace the default KeyWait time with the input from InputBox.

Any ideas?
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: fix for a faulty mouse

14 Nov 2015, 14:44

Try this:

Code: Select all

WaitTime := 0.06

Menu Tray, Icon, %A_WinDir%\System32\main.cpl  ; Set icon.
Menu Tray, NoStandard
Menu, Tray, Add, &Tweak Time ..., TweakTime
Menu Tray, Add, Exit, TrayExit
Menu Tray, Tip, Delayed Release

LButton::
Click down
Loop
{
KeyWait, LButton ; waits for the release
KeyWait, LButton, D T%WaitTime% ; waits T seconds for you to press LButton again
If ErrorLevel ; ErrorLevel is 1 if it times out. If the LButton was not pressed again, you likely purposefully released it
   Break ; exits the loop
; If you did press the LButton again, it goes back to the first KeyWait command and waits for another release
}
Click up
return

TrayExit:
ExitApp

TweakTime:
InputBox, WaitTime, Delayed Release - Tweak Time, Enter the time to wait in seconds,,,,,,,, %WaitTime%
Return
mkdabra
Posts: 8
Joined: 13 Nov 2015, 11:36

Re: fix for a faulty mouse

14 Nov 2015, 16:04

Works great! Thank you, guys!
the_player
Posts: 1
Joined: 02 Mar 2016, 08:27

Re: fix for a faulty mouse

02 Mar 2016, 08:29

Hello. The script works flawlesly, but could someone modify it to work with mouse 2 and 4-5 buttons? Thanks.
Guest

Re: fix for a faulty mouse

04 Mar 2016, 13:24

Anyone? I tried to do it myself, but RButton started to work like LButton.

Return to “Ask For Help”

Who is online

Users browsing this forum: anhnha, Bacon19331, Bing [Bot], casperharkin, Google [Bot], littlegandhi1199, Marius I, sobuj53, Xeo786 and 43 guests