disfated Posted February 15, 2011 Posted February 15, 2011 Hi everybody. Find nothing in help or forum search about what I would like to do: I need function that ask user to indicate a point on the screen. It simply waits till user clicks somewhere on the screen and then returns the coordinates of the point clicked by the user. If my description is clear and you have any ideas how it can be done, please help me PS. Don't sugest to input coordinates from keyboard.
Moderators Melba23 Posted February 15, 2011 Moderators Posted February 15, 2011 disfated,Try a combination of MouseGetPos and _IsPressed in a While...WEnd loop. I am surprised you did not run across the first of those in your search through the Help file. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
disfated Posted February 15, 2011 Author Posted February 15, 2011 Great! _IsPressed!Searched for WaitPress, WaitClick, WaitKey ... all about wait.Now I know what to do. Thanks again!
wolf9228 Posted February 15, 2011 Posted February 15, 2011 Hi everybody. Find nothing in help or forum search about what I would like to do: I need function that ask user to indicate a point on the screen. It simply waits till user clicks somewhere on the screen and then returns the coordinates of the point clicked by the user. If my description is clear and you have any ideas how it can be done, please help me PS. Don't sugest to input coordinates from keyboard. expandcollapse popup#include <WinAPI.au3> #include <WindowsConstants.au3> #include <StructureConstants.au3> HotKeySet("{ESC}", "Terminate") OnAutoItExitRegister("Cleanup") Const $tagMSLLHOOKSTRUCT = "int x;int y;DWORD mouseData;" & _ "DWORD flags;DWORD time;ULONG_PTR dwExtraInfo" Global $MouseHook , $MSLLHOOKSTRUCT , $MouseProc , $MouseHook , $PosArray[4] Global $hmod = _WinAPI_GetModuleHandle(0) , $Test = False RegistrationPointGuessing(0,0,@DesktopWidth,@DesktopHeight) While 1 if $Test = True Then MsgBox(0,"Msg","right Guess") $Test = False EndIf WEnd Func RegistrationPointGuessing($L,$T,$W,$H) if Not ($MouseHook) Then $MSLLHOOKSTRUCT = DllStructCreate($tagMSLLHOOKSTRUCT) $MouseProc = DllCallbackRegister("LowLevelMouseProc", "long", "int;wparam;lparam") $MouseHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL,DllCallbackGetPtr($MouseProc),$hmod) EndIf $PosArray[0] = $L $PosArray[1] = $T $PosArray[2] = $W $PosArray[3] = $H EndFunc ;http://msdn.microsoft.com/en-us/library/ms644986%28v=vs.85%29.aspx Func LowLevelMouseProc($nCode,$wParam,$lParam) If $nCode < 0 Then _ Return _WinAPI_CallNextHookEx($MouseHook, $nCode, $wParam, $lParam) $L = $PosArray[0] $T = $PosArray[1] $W = $PosArray[2] $H = $PosArray[3] $x = DllStructGetData($MSLLHOOKSTRUCT,1) $y = DllStructGetData($MSLLHOOKSTRUCT,2) $mouseData = DllStructGetData($MSLLHOOKSTRUCT,3) $flags = DllStructGetData($MSLLHOOKSTRUCT,4) $time = DllStructGetData($MSLLHOOKSTRUCT,5) $dwExtraInfo = DllStructGetData($MSLLHOOKSTRUCT,6) Switch $wParam Case $WM_LBUTTONDOWN Case $WM_LBUTTONUP if ($x >= $L And $x <= ($L + $W) And $y >= $T And $y <= ($T + $H)) Then $Test = True Case $WM_MOUSEMOVE Case $WM_MOUSEWHEEL Case $WM_MOUSEHWHEEL Case $WM_RBUTTONDOWN Case $WM_RBUTTONUP EndSwitch Return _WinAPI_CallNextHookEx($MouseHook, $nCode, $wParam, $lParam) EndFunc Func Cleanup() _WinAPI_UnhookWindowsHookEx($MouseHook) DllCallbackFree($MouseProc) EndFunc Func Terminate() Exit 0 EndFunc صرح السماء كان هنا
disfated Posted February 17, 2011 Author Posted February 17, 2011 (edited) wolf9228, thanks for your sample. it really helped me to do exactly what I need. Also used KeyboardHook to toggle mouse capturing by pressing Shift and some other key press proccessings.btw, there's mistake in your sample - $MSLLHOOKSTRUCT must be created inside LowLevelMouseProc() on the basis of $lParam, not in RegistrationPointGuessing().Here what I've got. Maybe it will be useful for someone...expandcollapse popup#include <WinAPI.au3> #include <WindowsConstants.au3> #include <StructureConstants.au3> HotKeySet("{ESCAPE}", "Terminate") OnAutoItExitRegister("Cleanup") Global Const $tagMSLLHOOKSTRUCT = 'int x;int y;DWORD mouseData;DWORD flags;DWORD time;ULONG_PTR dwExtraInfo' Global $hModule = _WinAPI_GetModuleHandle(0) Global $hMouseProc = DllCallbackRegister("LowLevelMouseProc", "long", "int;wparam;lparam") Global $pMouseProc = DllCallbackGetPtr($hMouseProc) Global $hMouseHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, $pMouseProc, $hModule) Global $hKeyboardProc = DllCallbackRegister("LowLevelKeyboardProc", "long", "int;wparam;lparam") Global $pKeyboardProc = DllCallbackGetPtr($hKeyboardProc) Global $hKeyboardHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, $pKeyboardProc, $hModule) Global $enable = False While 1 WEnd ; http://msdn.microsoft.com/en-us/library/ms644986(v=vs.85).aspx Func LowLevelMouseProc($nCode, $wParam, $lParam) If $nCode >= 0 And $wParam = $WM_LBUTTONUP Then If $enable Then ; http://msdn.microsoft.com/en-us/library/ms644970(v=vs.85).aspx Local $MSLLHOOKSTRUCT = DllStructCreate($tagMSLLHOOKSTRUCT, $lParam) Local $x = DllStructGetData($MSLLHOOKSTRUCT, 1) Local $y = DllStructGetData($MSLLHOOKSTRUCT, 2) ConsoleWrite('Click at (' & $x & ', ' & $y & ')' & @CRLF) EndIf EndIf Return _WinAPI_CallNextHookEx($hMouseHook, $nCode, $wParam, $lParam) EndFunc ; http://msdn.microsoft.com/en-us/library/ms644985(VS.85).aspx Func LowLevelKeyboardProc($nCode, $wParam, $lParam) If $nCode >= 0 Then ; http://msdn.microsoft.com/en-us/library/ms644967(v=VS.85).aspx Local $KBDLLHOOKSTRUCT = DllStructCreate($tagMSLLHOOKSTRUCT, $lParam) ; http://msdn.microsoft.com/en-us/library/dd375731(v=VS.85).aspx Local $vkCode = DllStructGetData($KBDLLHOOKSTRUCT, 1) If $vkCode = 0x10 Or $vkCode = 0xA0 or $vkCode = 0xA1 Then ; Shifts Switch $wParam Case $WM_KEYDOWN ConsoleWrite('Enable click capture' & @CRLF) $enable = True Case $WM_KEYUP ConsoleWrite('Disable click capture' & @CRLF) $enable = False EndSwitch ElseIf $wParam = $WM_KEYUP And ($vkCode >= 0x30) And ($vkCode <= 0x39) Then ; 0 - 9 ConsoleWrite('Sector set: ' & ($vkCode - 0x30) & @CRLF) ElseIf $wParam = $WM_KEYUP And ($vkCode >= 0x60) And ($vkCode <= 0x69) Then ; NumPad 0 - NumPad 9 ConsoleWrite('Sector set: ' & ($vkCode - 0x60) & @CRLF) EndIf EndIf Return _WinAPI_CallNextHookEx($hMouseHook, $nCode, $wParam, $lParam) EndFunc Func Cleanup() _WinAPI_UnhookWindowsHookEx($hMouseHook) _WinAPI_UnhookWindowsHookEx($hKeyboardHook) DllCallbackFree($hMouseProc) DllCallbackFree($hKeyboardProc) EndFunc Func Terminate() Exit 0 EndFunc Edited February 17, 2011 by disfated
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