Frogscape Posted March 14, 2010 Share Posted March 14, 2010 I am trying to get a left mouse to click when ever the mouse pointer passes over (or hovers over) a specific button. The idea is that when the user slowly moves the mouse vertically from the top to bottom of the message box the pointer passes over button 1 (called detect pointer) the mouse automatically clicks button 2 (called freeze). The problem is that I need help detecting when the mouse pointer is over button 1. How do I write this so the program understands this and send out a click? Thanks #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 230, 297, 303, 543) $Button1 = GUICtrlCreateButton("detect pointer", 80, 100, 75, 25, $WS_GROUP) $Button2 = GUICtrlCreateButton("FREEZE", 80, 128, 75, 25, $WS_GROUP) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### $var = [CLASS:Button; INSTANCE:1] ; error: how to define when mouse is over this button is the problem If $var > 1 Then ;If mouse hovers over button 1 then click left mouse MouseClick("left") ; click once on left mouse Sleep(3500) ;Pause to let user view action Else EndIf While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Link to comment Share on other sites More sharing options...
Yashied Posted March 14, 2010 Share Posted March 14, 2010 #Include <GUIConstantsEx.au3> #Include <WinAPI.au3> Global $Over = False $Form1 = GUICreate('Form1', 230, 297, 303, 543) $Button1 = GUICtrlCreateButton('detect pointer', 80, 100, 75, 25) $Button2 = GUICtrlCreateButton('FREEZE', 80, 128, 75, 25) GUISetState(@SW_SHOW) $hWnd = ControlGetHandle(WinGetHandle('Form1'), '', '[CLASS:Button; INSTANCE:1]') While 1 $tPoint = _WinAPI_GetMousePos() If _WinAPI_WindowFromPoint($tPoint) = $hWnd Then If Not $Over Then ; Do something ConsoleWrite('Over' & @CR) $Over = 1 EndIf Else If $Over Then ; Do something ConsoleWrite('Lost' & @CR) $Over = 0 EndIf EndIf $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEndBut if it's AutoIt window, you need to use GUIGetCursorInfo(). NassauSky 1 My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
Frogscape Posted March 14, 2010 Author Share Posted March 14, 2010 (edited) #Include <GUIConstantsEx.au3> #Include <WinAPI.au3> Global $Over = False $Form1 = GUICreate('Form1', 230, 297, 303, 543) $Button1 = GUICtrlCreateButton('detect pointer', 80, 100, 75, 25) $Button2 = GUICtrlCreateButton('FREEZE', 80, 128, 75, 25) GUISetState(@SW_SHOW) $hWnd = ControlGetHandle(WinGetHandle('Form1'), '', '[CLASS:Button; INSTANCE:1]') While 1 $tPoint = _WinAPI_GetMousePos() If _WinAPI_WindowFromPoint($tPoint) = $hWnd Then If Not $Over Then ; Do something ConsoleWrite('Over' & @CR) $Over = 1 EndIf Else If $Over Then ; Do something ConsoleWrite('Lost' & @CR) $Over = 0 EndIf EndIf $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd But if it's AutoIt window, you need to use GUIGetCursorInfo(). Thank you for the quick response and taking the time to write that awsome code. It work too perfectly! I also tried GUIGetCursorInfo(), as you suggested, and that also works too. Thank you. Edited March 14, 2010 by Frogscape 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