Use WSH to send key strokes to an app? 
Author Message
 Use WSH to send key strokes to an app?

Sorry - I don't know too much about WSH, but I'd like to know if it's
possible to send keystrokes, namely "alt+enter", to an aplication.  If it's
possible, what keywords should I use in my search at MS' WSH site?  If you
want to know why I want to do this (you might find it interesting), read
on...

When I login, I want to open Windows Media Player automatically in full
screen mode to play a sound and visualization while all my extentions and
stuff loads (yes, of course I'm aware that it'll take even more time by
loading wmplayer, but it'll give me something to look at, and if I get sick
of it, I can just turn it off).  Anyway, I went to one MS' web page that
said to insert the command-line switch "/fullscreen" to make it start in
full screen mode, but it doesn't (maybe it doesn't work in 7.0 - only in
6.4).  So, I want to use WSH to send the alt+enter keystroke (if it's
possible), to make it go fullscreen.

Thanks for your help
-Shawn



Mon, 19 May 2003 03:00:00 GMT  
 Use WSH to send key strokes to an app?
The Send Keys method requires that you have the latest version of WSH.

Set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys "%~"

should send Alt plus Enter as keystrokes.

Steve


Quote:
> Sorry - I don't know too much about WSH, but I'd like to know if it's
> possible to send keystrokes, namely "alt+enter", to an aplication.  If
it's
> possible, what keywords should I use in my search at MS' WSH site?  If you
> want to know why I want to do this (you might find it interesting), read



Mon, 19 May 2003 03:00:00 GMT  
 Use WSH to send key strokes to an app?
You need to use then AppActivate and SendKeys methods of WScript.Shell
object. The text you use with AppActivate must be unique and appears in the
title bar of the running application for . If you plan to send multiple
keystrokes to the application. Break them in to individual functions

    <Alt-F>         Open the File Menu
    P                   Select Print/open print dialog box
    <Enter>        Start printing/close print dialog box

Send each group of keystrokes with its own AppActivate and SendKeys pair.
Then by trail-and-error determine the correct amout of of delay time needed
between each of these pairs.

For sending only an <Alt-Enter>, use the following.

   Set oWS = WScript.CreateObject("WScript.Shell")

   oWS.AppActivate "MyApplication"
   oWS.SendKeys "%~"
   WScript.Sleep (100)



Tue, 20 May 2003 03:00:00 GMT  
 Use WSH to send key strokes to an app?
Why does %~ stand for <alt>-enter?  Did I miss the documentation as to what
each key is represented by?
--
Eli Allen


Quote:
> You need to use then AppActivate and SendKeys methods of WScript.Shell
> object. The text you use with AppActivate must be unique and appears in
the
> title bar of the running application for . If you plan to send multiple
> keystrokes to the application. Break them in to individual functions

>     <Alt-F>         Open the File Menu
>     P                   Select Print/open print dialog box
>     <Enter>        Start printing/close print dialog box

> Send each group of keystrokes with its own AppActivate and SendKeys pair.
> Then by trail-and-error determine the correct amout of of delay time
needed
> between each of these pairs.

> For sending only an <Alt-Enter>, use the following.

>    Set oWS = WScript.CreateObject("WScript.Shell")

>    oWS.AppActivate "MyApplication"
>    oWS.SendKeys "%~"
>    WScript.Sleep (100)



Tue, 20 May 2003 03:00:00 GMT  
 Use WSH to send key strokes to an app?
From the chm file for Windows Scripting Host:

To specify keys combined with any combination of the SHIFT, CTRL, and ALT
keys, precede the key code with one or more of the following codes:

Key Code
SHIFT +
CTRL ^
ALT %

and for other special keys

Key Code
BACKSPACE {BACKSPACE}, {BS}, or {BKSP}
BREAK {BREAK}
CAPS LOCK {CAPSLOCK}
DEL or DELETE {DELETE} or {DEL}
DOWN ARROW {DOWN}
END {END}
ENTER {ENTER}or ~


Quote:
> Why does %~ stand for <alt>-enter?  Did I miss the documentation as to
what
> each key is represented by?
> --
> Eli Allen



> > You need to use then AppActivate and SendKeys methods of WScript.Shell
> > object. The text you use with AppActivate must be unique and appears in
> the
> > title bar of the running application for . If you plan to send multiple
> > keystrokes to the application. Break them in to individual functions

> >     <Alt-F>         Open the File Menu
> >     P                   Select Print/open print dialog box
> >     <Enter>        Start printing/close print dialog box

> > Send each group of keystrokes with its own AppActivate and SendKeys
pair.
> > Then by trail-and-error determine the correct amout of of delay time
> needed
> > between each of these pairs.

> > For sending only an <Alt-Enter>, use the following.

> >    Set oWS = WScript.CreateObject("WScript.Shell")

> >    oWS.AppActivate "MyApplication"
> >    oWS.SendKeys "%~"
> >    WScript.Sleep (100)



Tue, 20 May 2003 03:00:00 GMT  
 Use WSH to send key strokes to an app?


Quote:
> Why does %~ stand for <alt>-enter?

Long answer:

Some convention is needed to represent keyboard keys that have no textual
representation.

You may have deduced that I hit the enter key a couple of times there; could
you tell how many times I hit the <ALT> key?


than "%"). Why they picked %~ instead of something else is beyond me. Why is
it that most of the world chose to drive on the right side of the road? In
some cases following the convention seems more important than understanding
how it was developed.

Short answer: because it does.

Quote:
>    Did I miss the documentation as to what
> each key is represented by?

Apparently you did, as it is there (assuming you have the most recent docs).

/Al

Quote:
> --
> Eli Allen



> > You need to use then AppActivate and SendKeys methods of WScript.Shell
> > object. The text you use with AppActivate must be unique and appears in
> the
> > title bar of the running application for . If you plan to send multiple
> > keystrokes to the application. Break them in to individual functions

> >     <Alt-F>         Open the File Menu
> >     P                   Select Print/open print dialog box
> >     <Enter>        Start printing/close print dialog box

> > Send each group of keystrokes with its own AppActivate and SendKeys
pair.
> > Then by trail-and-error determine the correct amout of of delay time
> needed
> > between each of these pairs.

> > For sending only an <Alt-Enter>, use the following.

> >    Set oWS = WScript.CreateObject("WScript.Shell")

> >    oWS.AppActivate "MyApplication"
> >    oWS.SendKeys "%~"
> >    WScript.Sleep (100)



Tue, 20 May 2003 03:00:00 GMT  
 Use WSH to send key strokes to an app?


picked %~ instead of something else is beyond me. ..."

Short answer: compatibility with existing VB syntax...

--
Michael Harris
Microsoft.MVP.Scripting
--

Please do not email questions - post them to the newsgroup...
--



Tue, 20 May 2003 03:00:00 GMT  
 Use WSH to send key strokes to an app?


Quote:



<alt> than "%"). Why they

Quote:
> picked %~ instead of something else is beyond me. ..."

> Short answer: compatibility with existing VB syntax...

I understand that. I was looking further back to when the original decision
on how to represent such keystrokes was made, whether in VB or even
something earlier. The point is that the why is not particularly important.

/Al

Quote:
> --
> Michael Harris
> Microsoft.MVP.Scripting
> --

> Please do not email questions - post them to the newsgroup...
> --



Wed, 21 May 2003 03:00:00 GMT  
 Use WSH to send key strokes to an app?
could one send mouse moves and clicks?
Quote:

> You need to use then AppActivate and SendKeys methods of WScript.Shell
> object. The text you use with AppActivate must be unique and appears in the



Fri, 23 May 2003 03:00:00 GMT  
 Use WSH to send key strokes to an app?
no


Quote:
> could one send mouse moves and clicks?


> > You need to use then AppActivate and SendKeys methods of WScript.Shell
> > object. The text you use with AppActivate must be unique and appears in

the


Fri, 23 May 2003 03:00:00 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Spawning process and sending key strokes to it???

2. Spawning process and sending key strokes to it???

3. Filter drop down menu using key strokes

4. Help with Send Keys and App Activate

5. Send keys to THIS app

6. Capture a key stroke

7. Key Stroke Grabber

8. How can I detect if a key is stroked when a script is running

9. Simulate key strokes on another page?

10. Using WSH to execute External App via IIS

11. Using WSH to execute External App via IIS

12. Launched apps using WSH are invisible!

 

 
Powered by phpBB® Forum Software