RogFleming Posted August 11, 2009 Share Posted August 11, 2009 While in a loop I what to check 2 mode the left mouse button is in either pressed, but when press when the user releases the button. So the first is to get a mouse pos when the user left clicks on the mouse, then get the mouse pos when the user releases. If _IsPressed("01", $dll) Then $upleft = MouseGetPos() If not _IsPressed("01", $dll) Then $lowerright = MouseGetPos() EndIf EndIf Purpose is to collect 2 seperate coordinates of the location of the mouse when the user clicks the left mouse button, and the other when the user releases the mouse button. See below an example I did with pressing the left button and then proessing the right button to get the 2 coordinates. Func _location() While 1 Sleep ( 25 ) ToolTip("Left click on the upper left corner and right click on the lower right corner of the desired area.",10,50) If _IsPressed("01", $dll) Then $upleft = MouseGetPos() ToolTip("You have selected the upper left corner of the target area.",$upleft[0],$upleft[1]) ElseIf _IsPressed("02", $dll) Then $lowerright = MouseGetPos() ToolTip("You have selected the lower right corner of the target area.",$lowerright[0],$lowerright[1]) targetbox();draws a retangle on the screen based on the collected coordinates EndIf WEnd EndFunc Thanks, Roger Link to comment Share on other sites More sharing options...
RogFleming Posted August 11, 2009 Author Share Posted August 11, 2009 Figured out my own solution: Func _location() While 1 ;Sleep ( 1000 ) ToolTip("Left click on the upper left corner and drag the mouse to the lower corner of the desired area.",10,50) If _IsPressed("01", $dll) Then GUIDelete() $upleft = MouseGetPos() ToolTip("You have selected the upper left corner of the target area.",$upleft[0],$upleft[1]) Do $lowerright = MouseGetPos() Until Not _IsPressed("01", $dll) ToolTip("You have selected the lower right corner of the target area.",$lowerright[0],$lowerright[1]) targetbox() EndIf WEnd EndFunc Link to comment Share on other sites More sharing options...
smashly Posted August 11, 2009 Share Posted August 11, 2009 (edited) Hi, #include <Misc.au3> _location() Func _location() While (Not _IsPressed("1B")) ; Just so I can exit the function when Esc is pressed Sleep(10) ToolTip("Left click on the upper left corner and right click on the lower right corner of the desired area.",10,50) If _IsPressed("01") Then $upleft = MouseGetPos() ToolTip("You have selected the upper left corner of the target area.",$upleft[0],$upleft[1]) ;Do a loop while the left mouse button is still pressed While _IsPressed("01") ; Small sleep in the loop to save cpu use Sleep(10) WEnd ;The user has let go of the left mouse button so we're out of the loop $lowerright = MouseGetPos() ToolTip("You have selected the lower right corner of the target area.",$lowerright[0],$lowerright[1]) ;this sleep is not needed, it's just so you can see the tooltip when the the left mouse button is released Sleep(1000) EndIf WEnd EndFunc Edit: Doh I was to slow to post.. glad you worked it out >_< Edited August 11, 2009 by smashly Link to comment Share on other sites More sharing options...
Authenticity Posted August 11, 2009 Share Posted August 11, 2009 expandcollapse popup#include <WinAPI.au3> #include <WindowsConstants.au3> HotKeySet('{ESC}', '_Close') If Not IsDeclared('WM_LBUTTONDOWN') Then Global Const $WM_LBUTTONDOWN = 0x0201 If Not IsDeclared('WM_RBUTTONDOWN') Then Global Const $WM_RBUTTONDOWN = 0x0204 If Not IsDeclared('WM_RBUTTONUP') Then Global Const $WM_RBUTTONUP = 0x0205 Global Const $tagMSLLHOOKSTRUCT = _ $tagPOINT & _ ';uint mouseData;' & _ 'uint flags;' & _ 'uint time;' & _ 'ulong_ptr dwExtraInfo;' Global $hFunc, $pFunc Global $hHook, $hMod Global $tRect = DllStructCreate($tagRECT) $hFunc = DllCallbackRegister('_MouseProc', 'lresult', 'int;int;int') $pFunc = DllCallbackGetPtr($hFunc) $hMod = _WinAPI_GetModuleHandle(0) $hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, $pFunc, $hMod) While 1 Sleep(20) WEnd Func _MouseProc($iCode, $iwParam, $ilParam) Local $tMSLL Local $iX, $iY If $iCode < 0 Then Return _WinAPI_CallNextHookEx($hHook, $iCode, $iwParam, $ilParam) $tMSLL = DllStructCreate($tagMSLLHOOKSTRUCT, $ilParam) $iX = DllStructGetData($tMSLL, 1) $iY = DllStructGetData($tMSLL, 2) Switch $iwParam Case $WM_LBUTTONDOWN DllStructSetData($tRect, 1, $iX) DllStructSetData($tRect, 2, $iY) Case $WM_LBUTTONUP DllStructSetData($tRect, 3, $iX) DllStructSetData($tRect, 4, $iY) AdlibEnable('_DelayFunc', 50) EndSwitch Return _WinAPI_CallNextHookEx($hHook, $iCode, $iwParam, $ilParam) EndFunc Func _Close() _WinAPI_UnhookWindowsHookEx($hHook) DllCallbackFree($hHook) Exit EndFunc Func _DelayFunc() AdlibDisable() _FlashRect($tRect) EndFunc Func _FlashRect($tRect, $iCount = 3, $iSleep = 150) Local $hDC Local $hPen, $hBrush Local $hOldBrush, $hOldPen Local $iOldROP $hDC = _WinAPI_GetDC(0) $hBrush = _WinAPI_GetStockObject($NULL_BRUSH) $hPen = _GDI_CreatePen(0, 5, 0xFFFFFF) ; PS_SOLID $hOldBrush = _WinAPI_SelectObject($hDC, $hBrush) $hOldPen = _WinAPI_SelectObject($hDC, $hPen) $iOldROP = _GDI_SETROP2($hDC, 7) ; R2_XORPEN For $i = 1 To $iCount Sleep($iSleep) _GDI_Rectangle($hDC, $tRect) Sleep($iSleep) _GDI_SETROP2($hDC, 7) _GDI_Rectangle($hDC, $tRect) Next _GDI_SETROP2($hDC, $iOldROP) _WinAPI_SelectObject($hDC, $hOldPen) _WinAPI_SelectObject($hDC, $hOldBrush) _WinAPI_DeleteObject($hPen) _WinAPI_DeleteObject($hBrush) _WinAPI_ReleaseDC(0, $hDC) EndFunc Func _GDI_Rectangle($hDC, $tRect) Local $aResult $aResult = DllCall('gdi32.dll', 'int', 'Rectangle', 'hwnd', $hDC, 'int', DllStructGetData($tRect, 1), 'int', DllStructGetData($tRect, 2), 'int', DllStructGetData($tRect, 3), 'int', DllStructGetData($tRect, 4)) If @error Then Return SetError(@error, @extended) Return $aResult[0] EndFunc Func _GDI_SETROP2($hDC, $iDrawMode) Local $aResult $aResult = DllCall('gdi32.dll', 'int', 'SetROP2', 'hwnd', $hDC, 'int', $iDrawMode) If @error Then Return SetError(@error, @extended) Return $aResult[0] EndFunc Func _GDI_CreatePen($iPenStyle = 0, $iWidth = 0, $iColor = 0) Local $aResult $aResult = DllCall('gdi32.dll', 'hwnd', 'CreatePen', 'int', $iPenStyle, 'int', $iWidth, 'int', $iColor) If @error Then Return SetError(@error, @extended) Return $aResult[0] EndFunc Link to comment Share on other sites More sharing options...
PsaltyDS Posted August 11, 2009 Share Posted August 11, 2009 While in a loop I what to check 2 mode the left mouse button is in either pressed, but when press when the user releases the button. So the first is to get a mouse pos when the user left clicks on the mouse, then get the mouse pos when the user releases. If _IsPressed("01", $dll) Then $upleft = MouseGetPos() If not _IsPressed("01", $dll) Then $lowerright = MouseGetPos() EndIf EndIf Purpose is to collect 2 seperate coordinates of the location of the mouse when the user clicks the left mouse button, and the other when the user releases the mouse button. See below an example I did with pressing the left button and then proessing the right button to get the 2 coordinates. Func _location() While 1 Sleep ( 25 ) ToolTip("Left click on the upper left corner and right click on the lower right corner of the desired area.",10,50) If _IsPressed("01", $dll) Then $upleft = MouseGetPos() ToolTip("You have selected the upper left corner of the target area.",$upleft[0],$upleft[1]) ElseIf _IsPressed("02", $dll) Then $lowerright = MouseGetPos() ToolTip("You have selected the lower right corner of the target area.",$lowerright[0],$lowerright[1]) targetbox();draws a retangle on the screen based on the collected coordinates EndIf WEnd EndFunc Thanks, Roger Perhaps you should track previous button status with a flag (single button example): #include <Misc.au3> HotKeySet("{ESC}", "_Quit") Global $f_Pressed = False, $avPos1, $avPos2 ToolTip("Left click on the upper left corner and right click on the lower right corner of the desired area.", 10, 50) While 1 Sleep(25) If $f_Pressed Then ; Button was pressed before If Not _IsPressed("01") Then ; Button is released $f_Pressed = False $avPos2 = MouseGetPos() ToolTip("Lower right: x = " & $avPos2[0] & ", y = " & $avPos2[1]) EndIf Else ; Button was not pressed before If _IsPressed("01") Then ; Button is pressed $f_Pressed = True $avPos1 = MouseGetPos() ToolTip("Upper left: x = " & $avPos1[0] & ", y = " & $avPos1[1]) EndIf EndIf WEnd Func _Quit() Exit EndFunc >_< Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
RogFleming Posted August 12, 2009 Author Share Posted August 12, 2009 You guys rock, It's great to see different points of view on how this process could be written. Roger 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