Jump to content

Recommended Posts

Posted

$pos = MouseGetPos() retrieves the current position of the mouse cursor.

But what about the buttons? Is there a way of checking whether the left mouse button is down (clicked)?

Do I need some DLL or such to accomplish this?

I'm a bit surprised that there is no function like MouseGetState("left") which would return information about the state.

Why? I want to check how fast my manual mouse clicks are performed - i.e how long my Mouse-Down times are.

Posted (edited)

#include <WindowsConstants.au3>
#Include <WinAPI.au3>

Global $mouseevent, $timer

$Gui = GuiCreate("", 300, 200)
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_SETCURSOR, 'WM_SETCURSOR')
GUIRegisterMsg($WM_MOUSEWHEEL, "WM_MOUSEWHEEL")

While 1
    $Msg = GUIGetMsg()
    If $Msg = -3 Then ExitLoop ; $GUI_EVENT_CLOSE
    If $mouseevent Then
        Beep(800,50)
        tooltip("Mouse event: " & $mouseevent)
        $timer = TimerInit()
        $mouseevent = ""
    EndIf
    If $timer And TimerDiff($timer) > 500 Then
        tooltip("")
        $timer = 0
    EndIf
WEnd

Func WM_SETCURSOR($hWnd, $iMsg, $iWParam, $iLParam)
    $iLParamhigh = BitShift($iLParam, 16) ;HiWord
    $iLParamlow  = BitAnd($iLParam, 0x0000FFFF) ;LoWord

    If $hWnd = $Gui And $iLParamlow = 1 And $iLParamhigh > 512 Then
        Switch $iLParamhigh
            Case $WM_LBUTTONDOWN
                $mouseevent = "LEFT-DOWN"
            Case $WM_LBUTTONUP
                $mouseevent = "LEFT-UP"
            Case $WM_RBUTTONDOWN
                $mouseevent = "RIGHT-DOWN"
            Case $WM_RBUTTONUP
                $mouseevent = "RIGHT-UP"
            Case $WM_MBUTTONDOWN
                $mouseevent = "MIDDLE-DOWN"
            Case $WM_MBUTTONUP
                $mouseevent = "MIDDLE-UP"
        EndSwitch
    EndIf
EndFunc

Func WM_MOUSEWHEEL($hWnd, $iMsg, $iwParam, $ilParam)
    If _WinAPI_HiWord($iwParam) > 0 Then
        $mouseevent = "SCROLL-UP"
    Else
        $mouseevent = "SCROLL-DOWN"
    EndIf
    Return 0
EndFunc

Edit: added detection of mouse scroll wheel.

PS - You could measure the delay between the down event, and the up event, and determine your "downtime".

Edited by Spiff59
  • 1 month later...
Posted

After testing this script a bit, I would also like to get info about current mouse position (x y).

I'm a little lost when it comes to using the $iLParamhigh and $iLParamlow vars in example above.. perhaps someone can give a hint?

Where can I read more about how to use WinAPI mouse functions? Best would be basic example code.

Thanks a lot!

Posted

After testing this script a bit, I would also like to get info about current mouse position (x y).

I'm a little lost when it comes to using the $iLParamhigh and $iLParamlow vars in example above.. perhaps someone can give a hint?

Where can I read more about how to use WinAPI mouse functions? Best would be basic example code.

Thanks a lot!

For get info about current mouse position (x y) see MouseGetPos function ! Posted Image

AutoIt 3.3.18.0 X86 - SciTE 4.4.6.0WIN 11 24H2 X64 - Other Examples Scripts

Posted

Ye. okay. I should have clarified..

If I want to get the position from WinAPI like the above events (write an own GetMousePos function)?

Posted

Ye. okay. I should have clarified..

If I want to get the position from WinAPI like the above events (write an own GetMousePos function)?

Where do you think MouseGetPos() gets your mouse position from?
Posted

Where do you think MouseGetPos() gets your mouse position from?

I don't know. That's why i asked for some someone who knows, one who can post an URL where I can read about this. Or even better, explain.

Posted

I don't know. That's why i asked for some someone who knows, one who can post an URL where I can read about this. Or even better, explain.

Personally i say why reinvent the wheel when MouseGetPos() handles the api interaction for you, BUT It's been done
Posted

Personally i say why reinvent the wheel when MouseGetPos() handles the api interaction for you, BUT It's been done

you have to use an array in the MouseGetPos()

$pos = MouseGetPos()

so something like this.

$pos[0]

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...