Script for mouse button to Send only when clicked quickly Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
A Keymaker
Posts: 455
Joined: 31 May 2022, 13:46
Location: Donjon du Château de Mérovingien

Script for mouse button to Send only when clicked quickly

Post by A Keymaker » 06 Jul 2023, 16:03

I would like to ask for help in producing a code that will act like so:


#1]
Detect if Backward Mouse Button / XButton1 is being physically held down

#2]
If XButton1 is held then do apply for this the XButton1Down state

#3]
Detect if more than 333 milliseconds have past

#4A]
If XButton1 is still being held after 333 milliseconds then keep acting normally as if this script was not executed i.e. keep applying XButton1Down state

#4B]
If XButton1 was released before 333 milliseconds have passed then execute

Code: Select all

Send {Shift Down}{Del Down}{Shift Up}{Del Up}{Down 2}

#5]
Reapply XButton1Up state and make the script ready to start over with awaiting for detection of XButton1


The reason behind the redundancy / robustness in it are conflicts with a global hotkey provided by program HotkeyP that when not taken extra care of by tiptoeing around leads to all kind of glitches in a program that this above Send command is destined for
Last edited by A Keymaker on 23 Sep 2023, 03:46, edited 2 times in total.

User avatar
A Keymaker
Posts: 455
Joined: 31 May 2022, 13:46
Location: Donjon du Château de Mérovingien

Re: Script for mouse button to Send only when clicked quickly  Topic is solved

Post by A Keymaker » 23 Sep 2023, 03:41

I managed to come up with such script:

Code: Select all

#Persistent

XButton1State := 0
XButton1DownTime := 0

SetTimer, CheckXButton1, 11 ; Re-checks XButton1 every 11 milliseconds

return

CheckXButton1:
    ; Checks if XButton1 is being physically held down
    GetKeyState, XButton1State, XButton1

    ; Checks if XButton1 is held down
    if (XButton1State = "D") {
        ; Check if XButton1 was just pressed down
        if (XButton1DownTime = 0) {
            XButton1DownTime := A_TickCount
        }
    } else {
        ; XButton1 has been released
        if (XButton1DownTime > 0) {
            ; Checks if more than 333 milliseconds have passed
            if (A_TickCount - XButton1DownTime >= 333) {
                ; Keeps applying XButton1Down state
                Send, {XButton1 Down}
            } else {
                ; XButton1 has been released before 333 milliseconds passed
                Send, {Shift Down}{Del Down}{Shift Up}{Del Up}{Down 2}
            }
            ; Re-applies XButton1Up state
            Send, {XButton1 Up}
        }
        ; Resets XButton1DownTime
        XButton1DownTime := 0
    }

return
But it seems to half-work - because it will ignore pressing of the XButton1 / Backward Mouse Button only if I physically keep pushing it down for more than around 1 second. I tried changing the milliseconds value from 333 to 111 but it did not help

How can this be, if I have no other scripts running?

User avatar
A Keymaker
Posts: 455
Joined: 31 May 2022, 13:46
Location: Donjon du Château de Mérovingien

Re: Script for mouse button to Send only when clicked quickly

Post by A Keymaker » 23 Sep 2023, 04:35

A Keymaker wrote:
23 Sep 2023, 03:41
[...]
How can this be, if I have no other scripts running?
I forgot about HotkeyP - apparently it was my setting of

Windows > Options > Mouse / Remote > Mouse > Delay mouse buttons > 555 ms

that was causing this, because after chaning this value to 222 the above script works seems to be working now A-OK

User avatar
A Keymaker
Posts: 455
Joined: 31 May 2022, 13:46
Location: Donjon du Château de Mérovingien

Re: Script for mouse button to Send only when clicked quickly

Post by A Keymaker » 23 Sep 2023, 07:17

Although there is one issue, which is rather beyond the scope of this topic - hence I created a new one: https://www.autohotkey.com/boards/viewtopic.php?f=76&t=121715

Post Reply

Return to “Ask for Help (v1)”