0

I need to make an AutoHotkey script that performs some action when and while the mouse button is pressed, then finishes when the mouse button is released.

For (a very simplified) example:

LButton::
  MouseGetPos x,y
  MsgBox %x%-%y%
LButton Up::MsgBox Foobar

Replacing the LButton with a keyboard key (e.g., LWin) makes it work correctly and moving the mouse cursor updates as expected while the key is held down, but using the mouse button only performs the LButton action one time. I need the hotkey action to continue occurring until the button is no longer being held.

1 Answer 1

1

After a bunch of query-term tweaking, I found a page that gives sample scripts for autofire.

I wasn’t sure that was what I wanted (even though it made sense) because as I said, the sample script already works just fine for keys, but I gave it a shot anyway. I tweaked the sample a bit and now it works as desired. (Actually, it is very similar to a solution I had already been using, but now it absorbs the button event, which solves the underlying problem that I led me to trying the aforementioned script.)

Hopefully I picked good keywords in this post so that anyone else who finds themselves in the same situation can find the/a solution faster than I did.

#SingleInstance,force
CoordMode, Mouse, Screen

LButton::
 While GetKeyState("LButton","p") {
    MouseGetPos x,y
    Tooltip %x%/%y%
    Sleep 75
 }
return

LButton Up::
    Tooltip Foobar
return
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.