1
votes

I'm trying to get the final dragging point (right button) with AutoHotKey:

~RButton::
CoordMode, Mouse, Screen

MouseGetPos, x0, y0


while GetKeyState("RButton")
{
    MouseGetPos, x1, y1
    Sleep, 10
}


MsgBox X: %x1% Y: %y1%
return

What it does is to wait the RightButton of the mouse to be pressed, gather x0 and y0 (inicial coordinates) and while the button is still pressed it gets the position of the mouse again (each 10 miliseconds).

After that it just displays the final coordinates.

It works nicely in normal environment but in this particular case this script needs to be executed in an application that takes control of the mouse when the right button is pressed. What that particular program does is to bring the mouse pointer to the center of the screen and when the button is realised it leaves it in the initial position. (x1, y1 are always the center of my screen, in pixels).

I believe that internally this program gathers the displacement of the mouse (while dragging) and use it for user interaction.

My question is: is there a way to obtain the real mouse input rather than looking at the screen and searching for the mouse pointer ( ~MouseGetPos) ? Is that achievable with AutoHotKey?

1
I don't understand the question. MouseGetPos should give you the current mouse position. To see how much the mouse moved, just get the absolute value of x0-x1 and of y0-y1Michael
You obviously skipped 90% of the post.Sturm
Interesting problem. I don't think it can be done per se, since to AHK, the mouse position is always the same; there's nothing to distinguish and nothing to measure. What kind of program are you working with? First thing that came to mind was an ego shooter, second thing was some kind of modeling/CAD software. Can you elaborate on what you're trying to achieve?MCL
It seems like you need some kind of mouse hook. There is no built in command for that, but Windows has a built in API. I am not familiar with it, but it may be something worth looking into.Michael

1 Answers

1
votes

You can use a mouse hook to get notified for every mouse movement. MSDN Hooks

To use hooks with AHK you have to use DllCall.

#Persistent

MouseHook := DllCall("SetWindowsHookEx", "int", 14  ; WH_MOUSE_LL = 14
    , "uint", RegisterCallback("MouseProc"), "uint", 0, "uint", 0)
return

MouseProc(nCode, wParam, lParam)
{
    global MouseHook
    Critical
    if wParam = 0x200 ; WM_MOUSEMOVE
    {
        ToolTip % NumGet(lParam+0,0,"int") ", " NumGet(lParam+4,0,"int")
    }

    return DllCall("CallNextHookEx", "uint", MouseHook
                    , "int", nCode, "uint", wParam, "uint", lParam)
}

Example Source