karthik001 Posted September 18, 2012 Share Posted September 18, 2012 Hi All, Firstly, Thanks to AutoIt, we have implemented automated solution in our project using AutoIt. This tool is wonderful. This is my first post and would be happy to get a solution for the follwoing issue. We have multiple instances of the same application running when running the AutoIt script. The control will normally be in one window and this will switch between other instance(window) of the application if required. We have used Handles to identify the correct window and through out our script, handle is used for any action(Example: Sending text using controlsend). The problem is when one instance of the application window is running the other instance of the window may get session timed out, so we want to send some dummy text to the other instance window at particular time intervals. We cannot use the main script to do this job. So we are planning to store the opened instance window's handles in a text file, then read the same using a separate script file and then sending the dummy text. The separate script can be triggered manually after triggering the main script. Please see the below code, Opt("SendKeyDelay", 20) Opt("SendKeyDownDelay", 50) Opt("WinTitleMatchMode", 4) $handle = "0x000905DA" WinActivate("$handle") for $i =1 to 100 ;ControlSend("Untitled - Notepad", "", "Edit1", "dummy text") ControlSend("$handle", "", "", "dummy text") Next Here, I can able to successfully activate the correct window. When using this line of code ControlSend("Untitled - Notepad", "", "Edit1", "dummy text") this is perfectly working as I expected. But when I use the following line of code ControlSend("$handle", "", "", "dummy text") this is not working as expected. I wonder that in my main automation file, I have through out used similar to this line of code to send the text(Using handles), but not working now. The only difference is that in my main automation file, I trigger the application from the script itself and I get the handle. Here, the application(notepad.exe) is already running and using AutoIt WIndow Info tool I get the window handle and directly using it. I have also tried using the exact control handle of edit control in the notepad but still no use. Please can anyone help me out in this issue? Thanks, Karthik Link to comment Share on other sites More sharing options...
iCode Posted September 18, 2012 Share Posted September 18, 2012 not sure what you're trying to do, but... $handle = "0x000905DA" and... WinActivate("$handle") isn't going to work unless the actual title of your window was "$handle" - the quotes need to be removed from the variable: WinActivate($handle) (same as WinActivate("0x000905DA")) could this be you're problem here... ControlSend("$handle", "", "", "dummy text") FUNCTIONS: WinDock (dock window to screen edge) | EditCtrl_ToggleLineWrap (line/word wrap for AU3 edit control) | SendEX (yet another alternative to Send( ) ) | Spell Checker (Hunspell wrapper) | SentenceCase (capitalize first letter of sentences) CODE SNIPPITS: Dynamic tab width (set tab control width according to window width) Link to comment Share on other sites More sharing options...
bogQ Posted September 18, 2012 Share Posted September 18, 2012 (edited) iCode maby he will need WinGetHandle()handle of the win chang every time there is something different when win is recreated, at that moment its new handle is decided, so working with WinActivate($handle) if you try to declare your handle as string 0x000905DA, is not gona workfuncs that will return handle and can be useful for this topic are:WinGetHandle('[ACTIVE]') *for something diffrent then [ACTIVE] parameter please look in help file under "Window Titles and Text (Advanced)"WinActive('')edit: so to backup iCode post@karthik001"" or '' is ment for strings, putting ("$handle") will not connect you with your variable named $handle cos you did ("$handle" instead ($handleControlSend($handle, "", "", "dummy text") shud work but only if you get your handle (or guess correctly that i hardly dont think anyone can do even if they are magicians) with some funcs that do realy check-return handle of win that you need to controllso use WinGetHandle('') or WinActive('') to get handle and connect it with ControlSend* command Edited September 20, 2012 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Link to comment Share on other sites More sharing options...
karthik001 Posted September 20, 2012 Author Share Posted September 20, 2012 Thanks icode and bogQ for the replies. I have changed the code to following, but still this is not working. $handle = "0x00020616" ;This I have taken using AutoIt WIndow Info tool WinActivate($handle) for $i =1 to 100 ;ControlSend("Untitled - Notepad", "", "Edit1", "dummy text") ControlSend($handle, "", "", "dummy text") Next For testing purpose, I have opened a notepad window, then directly got the window handle using AutoIt WIndow Info tool and used the same in code. Anyhow in reality, this is not going to happen. But as I explained in my earlier post, the handles of the windows will be identified by different .au3 script, I will save these handles in a file. I know how to identify the handle of the windows but in the main script I cannot send dummy text as it is designed for some other purpose. I will trigger another.au3 script which will read the handles from the already saved file and will send some dummy text to those windows at regular intervals to keep the session active. Regards, Karthik Link to comment Share on other sites More sharing options...
bogQ Posted September 20, 2012 Share Posted September 20, 2012 (edited) Guess i gotta work some more on my english, sometimes i wanna write something and it turn out like something else that even i don't understand when i re read it tomorrow $handle = "0x00020616" is text so if your win title isnt 0x00020616 you do need to use something that will return handle like WinGetHandle('[CLASS:Notepad]') or some other command from help file so this shud work $handle = WinActivate('[Class:Notepad]') If $handle Then for $i =1 to 100 ControlSend($handle, "", "", "dummy text") Next EndIf When you store some handle to some file i do think that you will need to get all win handless compare thenm to handle that you need and use real handle instead text on that win. from help file It is important to note that a window handle is [b]not[/b] classed as a number or string - it is its own special type. Edit: will reddit upper post cos it sound plain stupid Edited September 20, 2012 by bogQ karthik001 1 TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Link to comment Share on other sites More sharing options...
karthik001 Posted September 20, 2012 Author Share Posted September 20, 2012 Thanks bogQ. I tried as per your suggestion. That works like charm. Please see below lines of code: $handle = "0x001A0646" $var = WinList() For $i = 1 to $var[0][0] If $var[$i][1] = $handle Then $handle = $var[$i][1] EndIf Next WinActivate($handle) for $i =1 to 100 ;ControlSend("Untitled - Notepad", "", "Edit1", "dummy text") ControlSend($handle, "", "", "dummy text") Next However is it possible to send dummy text without activating the window i.e., without bringing the window to foreground? When I use the following line of code ControlSend("Untitled - Notepad", "", "Edit1", "dummy text") this is working even though without using the code line - WinActivate($handle) But when I use the following line of code ControlSend($handle, "", "", "dummy text") text is send only when the window is in foreground or I have to use the code line - WinActivate($handle) Regards, Karthik Link to comment Share on other sites More sharing options...
bogQ Posted September 20, 2012 Share Posted September 20, 2012 (edited) if win do allow you to send data when he dont have focus that its possible, some wins will not work others will alow you to do that so use WinGetHandle instead WinActivate and use ID of the controll your sending the command, in your case thats Edit1 so dont remove it unless you need to send data to some other controll Edited September 20, 2012 by bogQ karthik001 1 TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Link to comment Share on other sites More sharing options...
iCode Posted September 20, 2012 Share Posted September 20, 2012 in reference to bogQ's remarks, read about ControlSend() in the help file FUNCTIONS: WinDock (dock window to screen edge) | EditCtrl_ToggleLineWrap (line/word wrap for AU3 edit control) | SendEX (yet another alternative to Send( ) ) | Spell Checker (Hunspell wrapper) | SentenceCase (capitalize first letter of sentences) CODE SNIPPITS: Dynamic tab width (set tab control width according to window width) Link to comment Share on other sites More sharing options...
karthik001 Posted September 20, 2012 Author Share Posted September 20, 2012 Thank you very much bogQ. Unlike notepad window, my application window allows to send data without focus, so no further problem. Appreciate your help. Thanks, Karthik 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