boda17
boda17

Reputation: 1

If mouse is clicked, do one thing, if mouse is held down, do the normal thing

I want my code to be able to register if the mouse is clicked, and do something when that happens, but also to be able to register if the mouse is held down and not interrupt the mouse being held down if that is the case. For example,

    If AutoCAD is open
        If mbutton is clicked
            click the escape key
        If mbutton is held down
            be able to use the mbutton held down as usual
    End

I've tried a couple of different ways to do this but I don't have the knowledge to do this exactly. I've got the "If AutoCAD is open", and the "click the escape key" parts down, just not the "use the mbutton as normal if held down part"

Thanks for any help you can provide!

Upvotes: 0

Views: 283

Answers (2)

Elliot DeNolf
Elliot DeNolf

Reputation: 2999

This was a bit of a tricky one. Change the #IfWinExist line accordingly. You can adjust the duration to be what you would consider "holding" MButton

SetTitleMatchMode, 2

#IfWinExist AutoCAD

~MButton::
    duration := 100
    start := A_TickCount

    While(GetKeyState("MButton"))
    {
        if ((A_TickCount - start) > duration)
        {
            KeyWait, MButton
            Send {MButton Up}
            Return
        }
    }
    Send, {Escape}
    Return

#IfWinExist AutoCAD

Upvotes: 2

phil294
phil294

Reputation: 10822

If I understand you right, you are searching for the UP keyword:

The word UP may follow the name of a hotkey to cause the hotkey to fire upon release of the key rather than when the key is pressed down.

(documentation)

#if autocad()
MButton Up::
send {escape}
return
#if

autocad() {
    return true
}

Upvotes: 0

Related Questions