MDCT Posted June 1, 2009 Posted June 1, 2009 Hello again, guys. As usual I'm stuck and in need of enlightenment. This time, I need to detect if a user clicked a button from a specific non-Autoit GUI (a open/save dialog) and what button was clicked (save or cancel). Since it's non-AutoIt GUI, the GUIGetMsg() is not usable, right? I tried to search and read somewhere about this: Opt("WinTitleMatchMode", 4) if ControlClick("[ClASS:#32770]", "", "[CLASS:Button; INSTANCE:2]") = 1 then ConsoleWrite("Button clicked." & @LF) But the "if ControlClick" script always clicks the button, not detecting if the button is pressed or not. Now, the only thing I can think off is to register mouse hook. Should I use DllCallbackRegister("_LLMouseProc", "long", "int;wparam;lparam") that will detect each mouse click and active window.... or is there better, more efficient method to achieve this? Any help would be appreciated. Thank you.
Authenticity Posted June 1, 2009 Posted June 1, 2009 (edited) #include <GUIButton.au3> and use _GUICtrlButton_GetState() to get the state of the button using it's handle. If I'm not wrong, 610 is when the button is clicked.Edit: 620... Edited June 1, 2009 by Authenticity
Yashied Posted June 1, 2009 Posted June 1, 2009 You can use _IsPresssed(), but I think Hook would be preferable. 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...
MDCT Posted June 1, 2009 Author Posted June 1, 2009 @Authenticity: Yes, thank you, Authenticity. I think your idea (_GUICtrlButton_GetState) uses less CPU than using script that monitor mouse and window each time. I could get it to work. Strangely, it returns 108 as the state when a button is clicked... but, as long as it works, I'm happy. @Yashied: I would use _GUICtrlButton_GetState() instead the mousehook or if_pressed. With _GUICtrlButton_GetState(), I only monitoring a button, instead monitoring mouse and the active window. So, _GUICtrlButton_GetState() should use less CPU. Both of you thank you for trying to help. Take care.
Yashied Posted June 1, 2009 Posted June 1, 2009 Using _GUICtrlButton_GetState() you will most likely skip the event. You have to catch the release of a button rather than pressing it. 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...
MrCreatoR Posted June 1, 2009 Posted June 1, 2009 Look at WinControlSetEvent UDF.In this case you can do something like this:#include <WinControlSetEvent.au3> HotKeySet("^q", "_Quit") _WinControlSetEvent("[CLASS:#32770]", "Button2", "", "", "Clicked_Proc", "Button clicked.") While 1 Sleep(10) WEnd ;Warning: blocking of this function by window messages with commands such as "Msgbox()" can lead to unexpected behavior, ;the return to the system should be as fast as possible !!! Func Clicked_Proc($sParams, $hWnd, $nCtrlID) ConsoleWrite("Passed params: " & $sParams & @CRLF) EndFunc Func _Quit() Exit EndFunc Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team
MDCT Posted June 2, 2009 Author Posted June 2, 2009 Thanks for the info MrCreatoR. I tried _WinControlSetEvent but for some reason my double click is effected. I had to close the script to undo. I have added the _OnAutoItExit() inside the script, but it still won't unhook the mouse. I could prevent this by using second script, but I think it would take extra CPU usage. So, I use _GUICtrlButton_GetState. This will only work on the confirmation dialog when we are going to save file that the name already exists. #include <WinAPI.au3> #include <GUIButton.au3> #include <ButtonConstants.au3> While 1 Sleep(10) if _WinAPI_GetClassName(WinGetHandle("[ACTIVE]")) = "#32770" and StringInStr(WinGetText(WinGetHandle("[ACTIVE]")), "already exist") <> 0 then Sleep(10) local $hwndActive2 = WinGetHandle("[ACTIVE]"); Get active window ConsoleWrite("Dialog confirmation to replace file exists" & @CRLF) Sleep(1500) $buttonNo = ControlGetHandle("[ClASS:#32770]", "", "[CLASS:Button; INSTANCE:2]") while WinExists($hwndActive2) ConsoleWrite("No Button state is: " & _GUICtrlButton_GetState($buttonNo) & @CRLF) Sleep(40) If _GUICtrlButton_GetState($buttonNo) = 108 or _GUICtrlButton_GetState($buttonNo) = 620 Then $save=0 sleep(200) else $save=1 EndIf Sleep(10) WEnd ConsoleWrite("Save value is: " & $save & @CRLF) EndIf Sleep(10) WEnd I cannot just use If _GUICtrlButton_GetState($buttonNo) = 108 or 620 (note: on Scite the button state value is 108 if pressed, unlike notepad) to detect what the user selects. So, I use sleep(200) to wait for the dialog and check if the dialog exists or not. If after 200ms the button value is 108 or 620, the dialog doesn't exist... the script set the save value to 0, which means the user selects "No". It doesn't look smart, but it works for now. Don't forget, to check the script you need to save a file that already exists, so the confirmation dialog appears.
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