SendKeys

User avatar
Jezza
5StarLounger
Posts: 847
Joined: 24 Jan 2010, 06:35
Location: A Magic Forest in Deepest, Darkest, Kent

SendKeys

Post by Jezza »

I have a run.bat file that opens up an application, once that application is open I want to send the command Ctrl+P to it.
The only way I can think of doing this is to use the VB Script below where I run the batch file, wait a period of time (1000 for the moment) to allow connections to be made and then use SendKeys to pass Ctrl+P but it tells me a Object Required: WshShell

Any ideas how to send the key command once the application is active in the window?

Code: Select all

dim shell
set shell=createobject("wscript.shell")
shell.run "run.bat"

WScript.Sleep 1000 
WshShell.SendKeys "^P" 'This is the problem bit

set shell=nothing
Jerry
I’ll be more enthusiastic about encouraging thinking outside the box when there’s evidence of any thinking going on inside it

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: SendKeys

Post by HansV »

You already create a Shell object named shell, so instead of WshShell.SendKeys, use shell.SendKeys
Best wishes,
Hans

User avatar
Jezza
5StarLounger
Posts: 847
Joined: 24 Jan 2010, 06:35
Location: A Magic Forest in Deepest, Darkest, Kent

Re: SendKeys

Post by Jezza »

Whoops, thanks Hans

I have also realised the batch file was not returning so I prefixed it with Start
Jerry
I’ll be more enthusiastic about encouraging thinking outside the box when there’s evidence of any thinking going on inside it