Edit
Attach
Printable
topic end
<!-- * Set TOPICTITLE = Claus Brod: Rapid proto-typing (03 Mar 2006) --> <style type="text/css"> pre {background-color:#ffeecc;} </style> %STARTINCLUDE% <a name="03"></a> ---+++ [[BlogOnSoftware20060303][Rapid proto-typing]] (03 Mar 2006) Much to my dismay, I found myself in a situation where the following hack is useful. I shudder at the thought of actually using it because of its inherent instability, but sometimes it's better than a poke in the eye with C#. If you're automating an application which, while executing a command, may pop up error or warning messages and wait for user input, you may need to explicitly send a keystroke to that application. Fortunately, this is reasonably simple using [[http://msdn.microsoft.com/archive/en-us/wsh/htm/wsRunCscript.asp][cscript.exe]], the [[http://msdn.microsoft.com/library/en-us/script56/html/2b9476ce-54a7-4a00-b761-25bf9f36e83f.asp][WSH Shell object]] and <nop>VBscript: <pre> Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.<a href="http://www.winguides.com/scripting/reference.php?id=140">AppActivate</a> ("Appname as it appears in the main window title") WshShell.<a href="http://www.winguides.com/scripting/reference.php?id=149">SendKeys</a> "{ENTER}" </pre> <img src="%ATTACHURL%/windowtitle.jpg" align="right" /> While testing this, I learnt that the application name parameter to [[http://www.winguides.com/scripting/reference.php?id=140][<nop>AppActivate]] can actually be an abbreviation. For instance, if you run Word, its main window title is usually something like "gazonk.doc - Microsoft Word". =AppActivate= actually uses a simple best-match algorithm so that the following will still work as expected: <pre> Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.AppActivate ("Microsoft Word") WshShell.SendKeys "foo" </pre> The =SendKeys= method turns out to be pretty convenient since it allows to describe non-printable characters with a special notation, such as ={BREAK}= for the Break key, ={PGUP}= and ={PGDN}= for moving pagewise, ={DEL}=, ={HOME}=, all the function keys et cetera. %COMMENT{type="below" nonotify="on"}% --- %STOPINCLUDE%
to top
End of topic
Skip to action links
|
Back to top
Edit
|
Attach image or document
|
Printable version
|
Raw text
|
Refresh
|
More topic actions
Revisions: | r1.1
|
Total page history
|
Backlinks
You are here:
Blog
>
BlogOnSoftware20060303
r1.1 - 03 Mar 2006 - 09:15 -
ClausBrod
to top
Blog
This site
2017
:
12
-
11
-
10
2016
:
10
-
7
-
3
2015
:
11
-
10
-
9
-
4
-
1
2014
:
5
2013
:
9
-
8
-
7
-
6
-
5
2012
:
2
-
10
2011
:
1
-
8
-
9
-
10
-
12
2010
:
11
-
10
-
9
-
4
2009
:
11
-
9
-
8
-
7
-
6
-
5
-
4
-
3
2008
:
5
-
4
-
3
-
1
2007:
12
-
8
-
7
-
6
-
5
-
4
-
3
-
1
2006:
4
-
3
-
2
-
1
2005:
12
-
6
-
5
-
4
2004:
12
-
11
-
10
C++
CoCreate Modeling
COM & .NET
Java
Mac
Lisp
OpenSource
Scripting
Windows
Stuff
Changes
Index
Search
Maintenance
Impressum
Datenschutzerklärung
Home
Webs
Atari
Blog
Claus
CoCreateModeling
Klassentreffen
Main
Sandbox
Sommelier
TWiki
Xplm
Jump:
Copyright © 1999-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback