Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Inserting a string into an application

Reply
 
Old 06-28-2009   #11 (permalink)
mayayana


 
 

Re: Inserting a string into an application

>
Quote:

> Well, VBscript has a lot in common with VBA, and VBA
> has the typetext method
I've never used MS Office, but I'm guessing that you're
talking about the Word object model. (It helps if you
explain things. Don't assume that everyone uses MS
Office, or that everyone uses AutoIt, for that matter.)

VBA is the language used in MS Office automation.
The Word object model is an application of that language
that's only relevant within MS Word. In the same way, you
can use document.write from vbscript running in a webpage
inside IE. But document.write is not VBS. It's part of the IE
document object model. The document object and other
IE DOM scripting objects are only available in a webpage
loaded in IE.
Quote:

> 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
Quote:

> I'm trying to figure out.
>
If you try the script I posted you'll see that it
opens Notepad, writes text to Notepad, then saves
it as a file. The part that writes the text into the
Notepad window is very simple:

sh.SendKeys "this text is pasted."

The difference is that you're putting text on the
clipboard and then doing Ctrl + V with Sendkeys,
while the sample I posted is simply sending all of
the keys to write the text directly.

(Ctrl + V is another assumption you're making.
It's a standard Paste hotkey in Word and in
many other programs, but it's not guaranteed to
be universal.)

It gets tricky doing what you want to do. Programs
are not intended or designed to be able to control
each other, and with each version of Windows Microsoft
has reduced the options to do so for security reasons,
so any way you find to write text into the window of a
different running process is basically a hack that you'd
be better off accomplishing in some other way if possible.
It might not always work. But if your AutoIt method is
working then a simple SendKeys should work without
needing the clipboard:

s = "text to be pasted"
oWSH.SendKeys s

That works for me, but I don't know whether there
might be a limit in terms of the number of characters
you can send.





My System SpecsSystem Spec
Old 06-28-2009   #12 (permalink)
Todd Vargo


 
 

Re: Inserting a string into an application

Larry wrote:
Quote:

>
> Well, VBscript has a lot in common with VBA, and VBA has the typetext
method
Quote:

> 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
Quote:

> 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.
Your request is lacking some important details. From your code above, you
are using AutoIt to capture sText to the clipboard, but then it uses
SendKeys to paste it. Since the sText string is already created in the
vbscript, the capture to clipboard is a wasted step. Why don't you just use
SendKeys to paste sText directly to the app?

Set oWSH = CreateObject("WScript.Shell")
oWSH.SendKeys sText

If you still need further assistance, post details of what you are trying to
do and why, not how you think it should be done.

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

My System SpecsSystem Spec
Old 06-28-2009   #13 (permalink)
Todd Vargo


 
 

Re: Inserting a string into an application

Larry wrote:
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
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?
Yes.

oWSH.SendKeys sText

Note, because some characters have special meaning, you may need to replace
them with appropriate substitutes. i.e. +,^,%,~ and brackets {,},[,]

The following will replace + characters with {+} so they will not be
interpreted as {shift} when sent.

sText = Replace(sText, "+", "{+}")

Similar sequence would be used for other special characters. Read up on
SendKeys method for further details.

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

My System SpecsSystem Spec
Old 06-29-2009   #14 (permalink)
Larry


 
 

Re: Inserting a string into an application

Yes, this works, it's as simple as that:

Set oWSH = CreateObject("WScript.Shell")
oWSH.SendKeys sText

The only drawback is, when using this to insert the string into the editing
window of a blog, the test is "typed," appearing slowly, rather than
appearing all at once. Yet in other applications, like Word or Notepad, it
appears instantanously. However, that may just be a problem with my
computer.

Thanks for this.
Larry

My System SpecsSystem Spec
Old 06-29-2009   #15 (permalink)
Bob Barrows


 
 

Re: Inserting a string into an application

Larry wrote:
Quote:

> 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,
No, it doesn't. The Word application might provide that method, but it is
nothing that is supplied by VBA on its own.
Quote:

> 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.
>
There isn't. Each application has its own methods and properties for
handling input and output.

--
Microsoft MVP - ASP/ASP.NET - 2004-2007
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


My System SpecsSystem Spec
Old 06-29-2009   #16 (permalink)
Larry


 
 

Re: Inserting a string into an application

Bob Barrows wrote:
Quote:
Quote:

>> 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.
Quote:

> There isn't. Each application has its own methods and properties for
> handling input and output.
But there is, as another poster, Todd Vargo, has already shown me. And it's
something very simple:

Set oWSH = CreateObject("WScript.Shell")
oWSH.SendKeys sText

By the way, this is not the first time this has happened at this group. On a
couple of occasions I've asked if there was a way to do something very basic
using a .vbs file (like copying the selection in the active window), and
several people would tell me, no, there isn't, but then another poster comes
along and shows me how to do it, and it's very simple.

I think the reason this happens is that the things I use .vbs files for are
so basic and kindergarten level that they haven't occurred to advanced
users. :-)

Larry




My System SpecsSystem Spec
Old 06-30-2009   #17 (permalink)
Larry Serflaten


 
 

Re: Inserting a string into an application


"Larry" <larry328NOSPAM@xxxxxx> wrote
Quote:

> Set oWSH = CreateObject("WScript.Shell")
> oWSH.SendKeys sText
>
> By the way, this is not the first time this has happened at this group. On a
> couple of occasions I've asked if there was a way to do something very basic
> using a .vbs file (like copying the selection in the active window), and
> several people would tell me, no, there isn't, but then another poster comes
> along and shows me how to do it, and it's very simple.
>
> I think the reason this happens is that the things I use .vbs files for are
> so basic and kindergarten level that they haven't occurred to advanced
> users. :-)

Perhaps, but it could be all in the way the question is asked. For example,
the title of this thread. What you asked for isn't what you wanted. You wanted
to input a string to another application, you asked how to insert a string into
another application. Two very different things, depending on perspective....

LFS


My System SpecsSystem Spec
Old 06-30-2009   #18 (permalink)
Larry


 
 

Re: Inserting a string into an application

> Perhaps, but it could be all in the way the question is asked. For
example,
Quote:

> the title of this thread. What you asked for isn't what you wanted. You
wanted
Quote:

> to input a string to another application, you asked how to insert a string
into
Quote:

> another application. Two very different things, depending on
perspective....
Quote:

>
> LFS
I'm embarrassed to say, but I don't know the difference. Whether it's
inserting it or inputting it, is all the same to me. I wanted to stick that
string into the active window without using the Clipboard.

My System SpecsSystem Spec
Old 06-30-2009   #19 (permalink)
Bob Barrows


 
 

Re: Inserting a string into an application

Larry wrote:
Quote:

> Bob Barrows wrote:
>
Quote:
Quote:

>>> 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.
>
Quote:

>> There isn't. Each application has its own methods and properties for
>> handling input and output.
>
> But there is, as another poster, Todd Vargo, has already shown me.
> And it's something very simple:
>
> Set oWSH = CreateObject("WScript.Shell")
> oWSH.SendKeys sText
>
Sendkeys is not what comes to mind whenthe question of inserting something
comes up ... sorry.
Plus, I have a deeply ingrained aversion to Sendkeys, which I'm sure you
will develop as well once you start getting bitten in the behind by all its
associated problems ... ;-)

--
Microsoft MVP - ASP/ASP.NET - 2004-2007
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


My System SpecsSystem Spec
Old 06-30-2009   #20 (permalink)
mayayana


 
 

Re: Inserting a string into an application

>
Quote:

> By the way, this is not the first time this has happened at this group. On
a
Quote:

> couple of occasions I've asked if there was a way to do something very
basic
Quote:

> using a .vbs file (like copying the selection in the active window), and
> several people would tell me, no, there isn't, but then another poster
comes
Quote:

> along and shows me how to do it, and it's very simple.
>
> I think the reason this happens is that the things I use .vbs files for
are
Quote:

> so basic and kindergarten level that they haven't occurred to advanced
> users. :-)
>
I was the first to respond and gave you
the method you were looking for in that post.
But you didn't see it until it was presented in
a simpler form that you didn't have to think
about.

The problem is not that you're at kindergarten
level, but that you *want* to be at kindergarten
level -- looking for just the bit you need right now,
and avoiding the work of trying to understand more.

Bob Barrows and I both tried to explain a bit about
the landscape, to clarify your misunderstanding about
what's VBScript and what's an object, so that you could
get your answer *and* understand it. But you weren't
interested in that.

If you always approach it that way then you won't
know any more a year from now than you do now, and
you'll still be wondering why it's so hard to get an
answer.

Sorry if that sounds harsh, but this is a discussion group,
not a service, and it's also frustrating and timewasting for
people trying to help if you don't make an effort.


My System SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46