Xibalba Posted August 14, 2010 Share Posted August 14, 2010 $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. Link to comment Share on other sites More sharing options...
Spiff59 Posted August 14, 2010 Share Posted August 14, 2010 (edited) expandcollapse popup#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 August 14, 2010 by Spiff59 Link to comment Share on other sites More sharing options...
Xibalba Posted August 14, 2010 Author Share Posted August 14, 2010 Thanks, a lot. Link to comment Share on other sites More sharing options...
Xibalba Posted September 18, 2010 Author Share Posted September 18, 2010 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! Link to comment Share on other sites More sharing options...
wakillon Posted September 18, 2010 Share Posted September 18, 2010 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 ! AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
Xibalba Posted September 18, 2010 Author Share Posted September 18, 2010 Ye. okay. I should have clarified.. If I want to get the position from WinAPI like the above events (write an own GetMousePos function)? Link to comment Share on other sites More sharing options...
seandisanti Posted September 18, 2010 Share Posted September 18, 2010 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? Link to comment Share on other sites More sharing options...
Xibalba Posted September 19, 2010 Author Share Posted September 19, 2010 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. Link to comment Share on other sites More sharing options...
seandisanti Posted September 19, 2010 Share Posted September 19, 2010 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 Link to comment Share on other sites More sharing options...
Kalin Posted September 19, 2010 Share Posted September 19, 2010 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] Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now