![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| Guest | Inserting a string into an application I have various .vbs files in which (using AutoIt's ClipPut method) I put a string into the Clipboard and then paste the contents of the Clipboard into the active application, like this: Set oWSH = CreateObject("WScript.Shell") Set oAutoIt = WScript.CreateObject("AutoItX3.Control") oAutoIt.ClipPut(sText) oWSH.SendKeys"^v" Is it possible to insert a string directly into the active application, without transferring the string to the Clipboard and then pasting it? Thanks, Larry |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: Inserting a string into an application The following works for me on Win98SE. It opens Notepad, writes some text, opens the SaveAs dialogue, then saves the text as Sendkeys Demo.txt in the default folder. (Usually My Documents.) I seem to remember something about a problem with Sendkeys on Vista, though. There might be security issues or some such. You'll need to test it. Dim sh Set sh = CreateObject("WScript.Shell") sh.Run "notepad.exe" Do Until sh.AppActivate("Untitled - Notepad") Loop sh.SendKeys "Demonstration of Sendkeys. This file will be saved as SendKeys Demo.txt in My Documents." '-- Alt-file-SaveAs(%Fa) - opens the SaveAs dialogue. '-- backspace deletes the default file title (focus is on the file title textbox). '-- new file title: "SendKeys Demo". '-- ~ activates the Save button. sh.SendKeys "%Fa{backspace}SendKeys Demo~" set sh = nothing Quote: > I have various .vbs files in which (using AutoIt's ClipPut method) I put a > string into the Clipboard and then paste the contents of the Clipboard Quote: > the active application, like this: > > Set oWSH = CreateObject("WScript.Shell") > Set oAutoIt = WScript.CreateObject("AutoItX3.Control") > oAutoIt.ClipPut(sText) > oWSH.SendKeys"^v" > > Is it possible to insert a string directly into the active application, > without transferring the string to the Clipboard and then pasting it? > > Thanks, > Larry > > |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: Inserting a string into an application Doesn't VBScript have the equivalent of: Selection.TypeText sString that would work in any application? |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: Inserting a string into an application I didn't see any TypeText method or the equivalent in the VBScript User's Guide. http://msdn.microsoft.com/en-us/libr...7y(VS.85).aspx |
My System Specs![]() |
| | #5 (permalink) |
| Guest | Re: Inserting a string into an application On Jun 28, 1:58*pm, "Larry" <larry328NOS...@xxxxxx> wrote: Quote: > I didn't see any TypeText method or the equivalent in the VBScript User's > Guide. > > http://msdn.microsoft.com/en-us/libr...7y(VS.85).aspx board. You might find something in here that would work for you. ' <--------------- Begin Script ------------------------> Dim oWD, RangeOriginal, RangeCorrected, Cnt, Status Set oWD = WScript.CreateObject("Word.Application") oWD.Visible =false oWD.Documents.Add On Error Resume Next oWD.Selection.Paste If err.number<>0 then MsgBox "Clipboard was Empty" oWD.ActiveDocument.Close wdDoNotSaveChanges oWD.Quit Set oWD=Nothing Set oWD=Nothing WScript.Quit End If ' Set RangeOriginal=oWD.ActiveDocument.Range(0,oWD.Selection.End) If oWD.CheckSpelling(RangeOriginal)=False Then oWD.ActiveDocument.CheckSpelling Set RangeCorrected = oWD.ActiveDocument.Range(0,oWD.Selection.End) RangeCorrected.copy ' If RangeCorrected.Words.Count>7 Then Cnt=RangeCorrected.Words.Count Status= "The text beginning with: "&_ RangeCorrected.Words.Item(1)&" "&RangeCorrected.Words.Item(2)&" "&_ RangeCorrected.Words.Item(3)&"....."&vbCRLF&"and ending with: ....."&_ RangeCorrected.Words.Item(Cnt-2)&" "&RangeCorrected.Words.Item(Cnt-1) &_ " "&RangeCorrected.Words.Item(Cnt)&VbCrLf End If ' Else Status= "All words in the clipboard were spelled correctly" MsgBox Status End If ' oWD.ActiveDocument.Close wdDoNotSaveChanges oWD.Quit Set oWD=Nothing '< ------ end script -----------------------------------------------------------------> |
My System Specs![]() |
| | #6 (permalink) |
| Guest | Re: Inserting a string into an application > I didn't see any TypeText method or the equivalent in the VBScript User's Quote: > Guide. > without needing a 3rd-party tool to put the text on the clipboard. That's what I posted. I have no idea what "TypeText" is, or what your "Selection" object is. Why do you assume that people would know a method from some other language? |
My System Specs![]() |
| | #7 (permalink) |
| Guest | Re: Inserting a string into an application "Larry" <larry328NOSPAM@xxxxxx> wrote in message news:OlLV%23FA%23JHA.4168@xxxxxx Quote: >I have various .vbs files in which (using AutoIt's ClipPut method) I put a > string into the Clipboard and then paste the contents of the Clipboard > into > the active application, like this: > > Set oWSH = CreateObject("WScript.Shell") > Set oAutoIt = WScript.CreateObject("AutoItX3.Control") > oAutoIt.ClipPut(sText) > oWSH.SendKeys"^v" > > Is it possible to insert a string directly into the active application, > without transferring the string to the Clipboard and then pasting it? > > Thanks, > Larry used the AutoIt control. When I last used AutoIt, I would use it to wait until some desired window opened, partially by AutoIt's searching for some specified string displayed in the window. Then I would have AutoIt move the cursor to the desired spot on the screen and click the desired spot or use SendKeys to insert the string. Read AutoIt's online documentation at http://www.autoitscript.com/autoit3/docs/. One section you will especially want to read is using the AutoIt Window Info Tool and the rest of the Using AutoIt section should give you the rest of the info you need. -Paul Randall |
My System Specs![]() |
| | #8 (permalink) |
| Guest | Re: Inserting a string into an application Well, VBscript has a lot in common with VBA, and VBA has the typetext method by which a string can be inserted directly into a document, so I thought there might be something similar to that with scripting. In any case, I didn't understand your message. It was about creating and saving a txt file, it wasn't about inserting a string of text, which is what I'm trying to figure out. To repeat, this is what I do with several of my .vbs files, which I run using Winkey. A string has already been created, it is transferred to the Clipboard, and then it is pasted into whatever application is the active application: Set oWSH = CreateObject("WScript.Shell") Set oAutoIt = WScript.CreateObject("AutoItX3.Control") oAutoIt.ClipPut(sText) oWSH.SendKeys"^v" I simply wanted to see if there was an even simpler way of doing the same thing, not involving putting the string in the Clipboard but inserting the string directly. Larry |
My System Specs![]() |
| | #9 (permalink) |
| Guest | Re: Inserting a string into an application What I'm doing has nothing to do with looking for any particular window. The window I want to paste or insert into is already active. Think of this as the equivalent of pressing Ctrl+V to paste the Clipboard contents into the active window, except that what I'm doing here is pasting or inserting a string that's been created in a .vbs file. |
My System Specs![]() |
| | #10 (permalink) |
| Guest | Re: Inserting a string into an application VBA comes in many flavors, a different one for each of the applications within the Microsoft Office Suite. These VBA versions have special knowledge of the application, but can't necessarily do these special things to other applications. VBScript also does not have this ability. It can only do a generic SendKeys. AutoIt can look for a specific control within a window, and perhaps cause VBScript's SendKeys to send the keystrokes to the spot you want. Lots of windows contain multiple controls, and VBScript isn't smart enough to send them to the proper control. Note that SendKeys is dumb, in that it just blindly sends keystrokes to whatever application is active. If an antivirus or other service pops up a message while VBScript is sending a group of keystrokes, the message will likely become the active window and get some or all of the keystrokes. -Paul Randall "Larry" <larry328NOSPAM@xxxxxx> wrote in message news:eqKsnFG%23JHA.4900@xxxxxx Quote: > What I'm doing has nothing to do with looking for any particular window. > The > window I want to paste or insert into is already active. Think of this as > the equivalent of pressing Ctrl+V to paste the Clipboard contents into the > active window, except that what I'm doing here is pasting or inserting a > string that's been created in a .vbs file. > > > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Re: Inserting LDAP server into connection string?? | VB Script | |||
| Find a string within a variable string | PowerShell | |||
| problems with $var | select-string -pattern $string -q | PowerShell | |||
| How export-csv deals with string versus string[] | PowerShell | |||
| String PRODUCT_NAME was not found in string table | Vista General | |||