Struggling to get a working script to prevent mouse 4&5 from sending multiple clicks within a certain timeframe

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
helpabrotherout
Posts: 2
Joined: 30 Apr 2024, 12:44

Struggling to get a working script to prevent mouse 4&5 from sending multiple clicks within a certain timeframe

30 Apr 2024, 12:52

My mouse 4 and mouse 5 is broken and when I click once, it will send 2-3 clicks within a few milliseconds, so I'm trying to prevent more than 1 from being sent when I only click once.

I've tried quite a few scripts and I wish I saved them, I've just overwritten the same one numerous times. At this point I feel like I've used a better one than this that was like 1 minor tweak away from being exactly what I needed, but I wasn't sure what to modify to get it to work.

These that I'm using now seem to kind of work, but I'm hoping someone can help me get something better. Basically I never, ever click my back/forward button very quickly at all, so I never need to send more than 1 click in less than 500ms, so I want it to prevent more than 1 click being sent it it detects 1+ in a span of less than 500ms.

Here's what I have so far (I realize this might be not even close to what I need, no judgment please):

Code: Select all

*XButton1::  
If (A_PriorHotkey=A_ThisHotkey && A_TimeSincePriorHotkey < 100) ;hyperclick  
Return  
sendinput {Blind}{XButton1 down}  
KeyWait, XButton1  
sendinput {Blind}{XButton1 up}  
Return  
---

Code: Select all

*XButton2::  
If (A_PriorHotkey=A_ThisHotkey && A_TimeSincePriorHotkey < 100) ;hyperclick  
Return  
sendinput {Blind}{XButton2 down}  
KeyWait, XButton2  
sendinput {Blind}{XButton2 up}  
Return
Please help me :(
helpabrotherout
Posts: 2
Joined: 30 Apr 2024, 12:44

Re: Struggling to get a working script to prevent mouse 4&5 from sending multiple clicks within a certain timeframe

01 May 2024, 19:57

I found and modified a script that works perfectly. i went with 100ms for the disable window, obviously if anyone uses this, modify this to your needs.

Code: Select all

#Requires AutoHotkey v2.0.13+

*XButton1::temp_disable('XButton1')
*XButton2::temp_disable('XButton2')

temp_disable(key) {
    static last := Map()                                        ; Stores last click times
        , wait_time := 500                                      ; Disable time length

    if (last.Has(key) && A_TickCount - last[key] < wait_time)   ; If not enough time has gone by
        return                                                  ;   Stop code from going further

    last[key] := A_TickCount                                    ; Update last send time
    Send('{' key '}')                                           ; Send key/button
}


[Mod edit: Replaced the pair of with code tags.]

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: CoffeeChaton and 139 guests