1
votes

I would like to change the input of a mouse when I click the left button and hold it. The usual left click action must remain. Let left click behave as it is, but if you click and hold, let it perform something like holding keyboard button P (or any other keyboard button).

Currently what I got is something like:

~LButton:: 
sleep 100
While (Getkeystate("LButton","P"))
{   

    Send, {M down}

}
Send, {M up}

Return

I am trying to figure out how to remove the click action when I want just to spam letter M.

1
Are you aware that your request would disable things like drag and drop/move or high lighting text with your mouse. Is this something you have thought about? - Robert Ilbrink
Yes I am aware. I just need this script to run while I play a game. Updated the question with what I got so far. - IamMashed

1 Answers

1
votes

The following should do what you want:

threshold := 100
LButton::
    CoordMode, Mouse, Screen ; needed to prevent some issues when clicking changes focus
    MouseGetPos, mXclick, mYclick ; save mouse position before sleep

    sleep % threshold

    ; mouse up, do normal click
    if (!GetKeyState("LButton", "P")) {
        MouseGetPos, mXcurr, mYcurr ; save mouse position before click
        Click %mXclick%, %mYclick%
        MouseMove, %mXcurr%, %mYCurr% ; restore mouse position
        return
    }

    while (GetKeyState("LButton", "P")) {
        Send {M down}
        Sleep 30
    }
    Send {M up}
return

You can play with the threshold, try different values and see how it works. Also all the MouseGetPos and MouseMove might not be needed, depends on what you want to happen.

Currently doubleClick will also be a little problematic, you need to doubleClick slower than the threshold but fast enough to register a doubleClick. This can probably be solved, so tell me if it's something you need.