icu Posted November 22, 2012 Share Posted November 22, 2012 Hi Everyone, I'm having problems getting my AutoIt script to interact with an application's control when I attempt to use ControlSend. As far as I can tell using the Window Info tool, the ID of the control keeps changing to a unique number every time the program is launched. This makes coding the ID number seem like an impossible task or perhaps I don't know what I'm doing. I've tried the usual Google search, Help File search, Forum search, playing around with different code options like changing function inputs and even using Send (which doesn't work). Can anyone please shed some light on how I'm using ControlSend because I'm sure I'm missing something but I don't know what I'm doing wrong. $i_PID_SQLite_Expert = Run("C:\Program Files (x86)\SQLite Expert Professional v3.1.6\SQLite Expert Professional.exe", "", @SW_MAXIMIZE) ConsoleWrite("$i_PID_SQLite_Expert = " & $i_PID_SQLite_Expert & @CRLF) $h_SQLite_Expert = WinWaitActive("SQLite Expert Professional 3.1.6.2082") If $h_SQLite_Expert <> 0 Then ConsoleWrite("WinWaitActive found title: SQLite Expert Professional 3.1.6.2082" & @CRLF) ControlSend("[CLASS:TdxBarControl]", "", "2034104", "!f") ;Previous values for ID according to Window Info include 2034104, 2426674, 2164300 If @error <> 0 Then ConsoleWrite("ControlSend !f success" & @CRLF) Else ConsoleWrite("ControlSend !f failure" & @CRLF) EndIf ControlSend("[CLASS:TdxBarControl]", "", "2426674", "n") $h_Database_Creation = WinWaitActive("Database Creation Properties") $s_Database_File = @ScriptDir & "\securities.db3" ControlSend("[CLASS:TcxCustomInnerTextEdit]", "", "460682", $s_Database_File) ControlSend("[CLASS:TcxComboBoxEx]", "", "658120", "32768{ENTER}{ENTER}") ProcessClose($i_PID_SQLite_Expert) Exit Console: >"C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Users\icu\Desktop\Options Expres\Stock_Scanner\Database creation script.au3" /autoit3dir "C:\Program Files (x86)\AutoIt3" /UserParams +>23:57:45 Starting AutoIt3Wrapper v.2.0.1.24 Environment(Language:0409 Keyboard:00000809 OS:WIN_7/Service Pack 1 CPU:X64 OS:X64) >Running AU3Check (1.54.19.0) from:C:\Program Files (x86)\AutoIt3 +>23:57:45 AU3Check ended.rc:0 >Running:(3.3.6.1):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "C:\Users\icu\Desktop\Options Expres\Stock_Scanner\Database creation script.au3" $i_PID_SQLite_Expert = 8076 WinWaitActive found title: SQLite Expert Professional 3.1.6.2082 ControlSend !f failure Screenshot of AutoIt Window Info: Thank you for any help. Link to comment Share on other sites More sharing options...
water Posted November 22, 2012 Share Posted November 22, 2012 Please check the help file and you will see that there many ways to specify a ControlID. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
icu Posted November 23, 2012 Author Share Posted November 23, 2012 (edited) @water: Thanks for your reply, while your link has increased my knowledge about referring to IDs, it hasn't shed light on why I can't get ControlSend() to work as I intend it to. I have modified my code according to the different methods for referring to the ID, however this does not fix the problem. One such broken code example is below: $i_PID_SQLite_Expert = Run("C:Documents and SettingsicuDesktopPAppsSQLite Expert Professional v3.1.6SQLite Expert Professional.exe", "", @SW_MAXIMIZE) ConsoleWrite("$i_PID_SQLite_Expert = " & $i_PID_SQLite_Expert & @CRLF) $h_SQLite_Expert = WinWaitActive("SQLite Expert Professional 3.1.6.2082") If $h_SQLite_Expert <> 0 Then ConsoleWrite('SUCCESS: WinWaitActive found title "SQLite Expert Professional 3.1.6.2082"' & @CRLF) Else ConsoleWrite('FAILURE: WinWaitActive did not find title "SQLite Expert Professional 3.1.6.2082"' & @CRLF) EndIf $i_Error_Check = ControlFocus("SQLite Expert Professional 3.1.6.2082", "", "[CLASS:TdxBarControl]") If $i_Error_Check = 1 Then ConsoleWrite("SUCCESS: ControlFocus found: [CLASS:TdxBarControl]" & @CRLF) $i_Error_Check = "" ElseIf $i_Error_Check = 0 Then ConsoleWrite("FAILURE: ControlFocus not found: [CLASS:TdxBarControl]" & @CRLF) $i_Error_Check = "" EndIf $i_Error_Check = ControlSend("SQLite Expert Professional 3.1.6.2082", "", "[CLASS:TdxBarControl]", "!f") If $i_Error_Check = 1 Then ConsoleWrite("SUCCESS: ControlSend !f" & @CRLF) $i_Error_Check = "" ElseIf $i_Error_Check = 0 Then ConsoleWrite("FAILURE: ControlSend !f" & @CRLF) $i_Error_Check = "" EndIf Exit The console outputs the following: >"C:Documents and SettingsicuMy DocumentsPortable AppsAutoIt3SciTe..autoit3.exe" /ErrorStdOut "C:Documents and SettingsicuDesktopAutoIt optionsXpressSQLite_New_DB_Test2.au3" $i_PID_SQLite_Expert = 3536 SUCCESS: WinWaitActive found title "SQLite Expert Professional 3.1.6.2082" SUCCESS: ControlFocus found: [CLASS:TdxBarControl] SUCCESS: ControlSend !f >Exit code: 0 Time: 4.485 According to the console read out, the ControlSend() function should work. Presumably [CLASS:TdxBarControl] takes the place of the ID that kept changing on me. However when I watch the script work the program does not respond to the ALT+F sent to it. If I change the code to the following it somehow works: $i_PID_SQLite_Expert = Run("C:Documents and SettingsicuDesktopPAppsSQLite Expert Professional v3.1.6SQLite Expert Professional.exe", "", @SW_MAXIMIZE) ConsoleWrite("$i_PID_SQLite_Expert = " & $i_PID_SQLite_Expert & @CRLF) $h_SQLite_Expert = WinWaitActive("SQLite Expert Professional 3.1.6.2082") If $h_SQLite_Expert <> 0 Then ConsoleWrite('SUCCESS: WinWaitActive found title "SQLite Expert Professional 3.1.6.2082"' & @CRLF) Else ConsoleWrite('FAILURE: WinWaitActive did not find title "SQLite Expert Professional 3.1.6.2082"' & @CRLF) EndIf $i_Error_Check = ControlFocus("SQLite Expert Professional 3.1.6.2082", "", "[CLASS:TdxBarControl]") If $i_Error_Check = 1 Then ConsoleWrite("SUCCESS: ControlFocus found: [CLASS:TdxBarControl]" & @CRLF) $i_Error_Check = "" ElseIf $i_Error_Check = 0 Then ConsoleWrite("FAILURE: ControlFocus not found: [CLASS:TdxBarControl]" & @CRLF) $i_Error_Check = "" EndIf Send("!f") Exit Console read out is the following: >"C:Documents and SettingsicuMy DocumentsPortable AppsAutoIt3SciTe..autoit3.exe" /ErrorStdOut "C:Documents and SettingsicuDesktopAutoIt optionsXpressSQLite_New_DB_Test2.au3" $i_PID_SQLite_Expert = 4024 SUCCESS: WinWaitActive found title "SQLite Expert Professional 3.1.6.2082" SUCCESS: ControlFocus found: [CLASS:TdxBarControl] >Exit code: 0 Time: 5.083 As can be seen from the above code, the ControlFocus() and Send() functions work together to get the script to work... but only some of the time. It seems to work 3/4 times but isn't reliable enough. I thought the whole reason ControlSend() was created was to get around reliability issues with Send(). If anyone one can help me with this I would really appreciate it. Edited November 25, 2012 by icu Link to comment Share on other sites More sharing options...
water Posted November 23, 2012 Share Posted November 23, 2012 Could you replace$i_Error_Check = ControlSend("SQLite Expert Professional 3.1.6.2082", "", "[CLASS:TdxBarControl]", "!f")with $i_Error_Check = ControlSend("SQLite Expert Professional 3.1.6.2082", "", "[CLASS:TdxBarControl]", "{ALTDOWN}f{ALTUP}")and give it a try? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
icu Posted November 25, 2012 Author Share Posted November 25, 2012 @water: Thank you for your suggestion. I'm afraid it isn't working. I've even tried to use ControlFocus() before the ControlSend() and I'm still none the wiser. Is it possible that a Windows application will resist automation using the Control functions despite the correct control ID being used? Link to comment Share on other sites More sharing options...
JohnOne Posted November 25, 2012 Share Posted November 25, 2012 @water: Thank you for your suggestion. I'm afraid it isn't working. I've even tried to use ControlFocus() before the ControlSend() and I'm still none the wiser. Is it possible that a Windows application will resist automation using the Control functions despite the correct control ID being used?very possible AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Bowmore Posted November 25, 2012 Share Posted November 25, 2012 From the information shown in AuInfo the most reliable method should be to use the control text. $i_Error_Check = ControlSend("SQLite Expert Professional 3.1.6.2082", "", "[TEXT:Main Menu]", "!f") "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted November 25, 2012 Moderators Share Posted November 25, 2012 Set it by position of the control. I think I wrote something, and I'm sure others have that get the control by position. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Malkey Posted November 26, 2012 Share Posted November 26, 2012 Try:- $i_Error_Check = ControlSend("SQLite Expert Professional 3.1.6.2082", "", "[CLASS:TdxBarControl:INSTANCE:7]", "!f") ; Sends "ALT+f". ;or $i_Error_Check = ControlSend("[CLASS:TdxBarControl:INSTANCE:7]", "", "TdxBarControl7", "!f") ; Sends "ALT+f". ;or with Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase ;One could use $i_Error_Check = ControlSend("3.1.6.2082", "", "TdxBarControl7", "!f") ; Sends "ALT+f". Alternatively, instead of "SQLite Expert Professional 3.1.6.2082", the window title, one can use "[CLASS:TfrmSCMain]", being the window class and not the control class as used in Post #1. Also, instead of "[CLASS:TdxBarControl:INSTANCE:7]" one can use just the ClassnameNN by itself "TdxBarControl7". Note: There could be another six instances of the class, TdxBarControl for ControlSend to send to. Or, if you specifically want to use the control Id, and, because Windows automatically assigns an Id value, try:- #include <WinAPI.au3> $hCtrlHandle = ControlGetHandle("SQLite Expert Professional 3.1.6.2082", "", "TdxBarControl7") $iCtrlId = _WinAPI_GetDlgCtrlID($hCtrlHandle) ; From #include <WinAPI.au3> file. $i_Error_Check = ControlSend("SQLite Expert Professional 3.1.6.2082", "", $iCtrlId, "!f") ; Sends "ALT+f". 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