MichaelCayouette Posted December 6, 2012 Share Posted December 6, 2012 Hi I'm new to AutoIt and this is probably a very basic question. I have the following script that I'm playing with. Run("WINWORD.EXE") WinWainActive("Document1 - Microsoft Word") Send("This is my test string") WinClose("Document1 - Microsoft Word") WinWaitActive("Microsoft Office Word") Send("!y") WinWaitActive("Save As") Send("c:\temp\test.doc") Only the word "This" gets send to the document and the rest of it "is my test string" ends up getting sent to the Save dialog box rather than the "C:\temp\test.doc". I'm sure I've missed something but I can't figure out what Thank you, Mike Link to comment Share on other sites More sharing options...
MichaelCayouette Posted December 6, 2012 Author Share Posted December 6, 2012 I haved also tried to use the ControlSend() command and all all that is send to the document is "T" but at least the "C:temptest.doc" is sent to the Save As file name dialog box. Why am I not able to sent a string to my document using send() or ControlSend()? Mike Link to comment Share on other sites More sharing options...
nitekram Posted December 6, 2012 Share Posted December 6, 2012 (edited) Not tested:Run("C:Program FilesMicrosoft OfficeOffice12winword.exe") WinWaitActive("Document1 - Microsoft Word") Send("This is my test string") sleep(1000) ; test this time WinClose("Document1 - Microsoft Word") WinWaitActive("Microsoft Office Word") Send("!y") WinWaitActive("Save As") Send("c:temptest.doc")Edit - Tested and appears to work Edited December 6, 2012 by nitekram 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow." WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator Link to comment Share on other sites More sharing options...
MichaelCayouette Posted December 6, 2012 Author Share Posted December 6, 2012 That worked, thank you. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted December 6, 2012 Moderators Share Posted December 6, 2012 If you are specifically using Word, I would do it this way (from the help file): #include <Word.au3> $oWordApp = _WordCreate(@DesktopDir & "Test.doc", 0, 0) Local $oDoc = _WordDocGetCollection($oWordApp, 0) $oDoc.Range.insertAfter("This is my text string.") _WordQuit($oWordApp, -1) "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
nitekram Posted December 7, 2012 Share Posted December 7, 2012 This might be off topic, but think it might need some attention. There are a few things that appear to not work correctly with the function Send().1. When using Alt, Shift, Ctrl with Send(), it sometimes locks the keys as described here.2. When sending a string as above, it appears that the Send() function does not complete before returning to the calling code.Maybe someone (dev) can revamp the function and fix these? 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow." WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator Link to comment Share on other sites More sharing options...
JohnOne Posted December 7, 2012 Share Posted December 7, 2012 You can also unlock them as describe in your link. I've never seen a send function not complete, perhaps you can provide an example. 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...
kaotkbliss Posted December 7, 2012 Share Posted December 7, 2012 I've had the Send() not complete many times What I do is find where it stops sending and create a new Send to follow. For example: Send("This") Send(" is my test") Send(" string.") Which has always solved my problem 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy! Link to comment Share on other sites More sharing options...
nitekram Posted December 7, 2012 Share Posted December 7, 2012 (edited) You can also unlock them as describe in your link. I've never seen a send function not complete, perhaps you can provide an example. OP provided an example - that is why I said that. Also, if it can be unlocked by code, why not just enter that code into the original function, as to not allow it to happen in the first place. I am just saying that it could be all inclusive, ie make sure it sends the complete line of text, and make sure it releases the keys that get stuck down when using it. EDIT added the code from OP Run("WINWORD.EXE") WinWainActive("Document1 - Microsoft Word") Send("This is my test string") WinClose("Document1 - Microsoft Word") WinWaitActive("Microsoft Office Word") Send("!y") WinWaitActive("Save As") Send("c:temptest.doc") Edited December 7, 2012 by nitekram 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow." WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator Link to comment Share on other sites More sharing options...
JohnOne Posted December 7, 2012 Share Posted December 7, 2012 Never experienced it. $MyString = "This is my string" _Send($MyString) Func _Send($sString) Local $aString = StringSplit($sString,"") For $i = 1 To $aString[0] Send($aString[$i]) Next EndFunc 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...
BrewManNH Posted December 7, 2012 Share Posted December 7, 2012 The Send command is prone to problems as it is, and should only be used in very specific cases. Adding more code to an already marginal use command wouldn't make much sense. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
JohnOne Posted December 7, 2012 Share Posted December 7, 2012 I don't know, I'm just above slightly confident that it would workaround the problem in the first post. 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...
nitekram Posted December 8, 2012 Share Posted December 8, 2012 (edited) The Send command is prone to problems as it is, and should only be used in very specific cases. Adding more code to an already marginal use command wouldn't make much sense.In my case, I use the Send command to script a type of form (really a script) that puts the same set of text chars everytime a new task is to be performed. Is there something else that could be used instead? Without a lot of extra code and time, filling in a form with tabs and pasted text sent via the Send command is a simple script to write.I don't know, I'm just above slightly confident that it wouldworkaround the problem in the first post.I will test this when I get back to office and see if it fixes the issue - as I got the same results as the OP with their code - I hard coded my path though. The Sleep command I put in did in fact fix the issue. Not sure if the text had been longer, the same Sleep time would have worked. Your code looks like it would make sure each character was sent. That in combination of the link I posted would be what I would think would be easy to code - not saying I could do it, but knowing what needs to be done, I could do it in AutoIt code. But I can understand if not too many people are using it then changing the existing code might not be worth it.EDIT I just thought of another work around, not tested, but sending the text to the clipboard and then using Send command to paste the text - with ctrl v, but you would still have to deal with the sticky keys. Edited December 8, 2012 by nitekram 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow." WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator Link to comment Share on other sites More sharing options...
BrewManNH Posted December 8, 2012 Share Posted December 8, 2012 ControlSend is more reliable than Send, because you specify the window and the exact control to send the text to. Send relies on the hope that the cursor is in the right place when you send the text, if anyone uses the keyboard or the mouse while Sending then that's not going to be the case. Also, Send requires the window to be the active window and visible, ControlSend can send to a minimized window and even works when the computer is locked which Send can't. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
JohnOne Posted December 8, 2012 Share Posted December 8, 2012 It is the users responsibility to make sure those conditions are met. Controlsend is increasingly as unreliable as send. with more and more custom controls becoming common. 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...
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