JackRap

Send function keystroke command to CMD window

6 posts in this topic

Hi,

I'm very new to all this so please excuse the newbie errors

I have a .bat command that opens an old DOS program in cmd. What I'd like to do is select the window and send the F3 keystroke.

RunWait ( @COMSPEC & " /c \\server\Shared\share\lm.bat", "\\server\Shared\share")
RunWait(WinWaitActive("C:\WINDOWS\system32\cmd.exe"))
WScript.Sleep 3000
WshShell.SendKeys("{F3}")

But it doesn't seem to be receiving the F3 command. Can more expert eyes see if I'm doing anything wrong?

 

Many thanks.

Share this post


Link to post
Share on other sites



Welcome Jack,

Not sure what you were thinking when coding the posted source. seems to be a mix of AutoIt3 and VBScript source code.
Assume: 

  • Line 1 works.
  • Line 2 is trying to shell the returncode of a winWaitActive() command :think: 
  • LIne 3 is a VBS command and will give an error when ran with AutoIt3
  • Line 4 seems to be a VBS/AutoIt3 made up syntax, obviously also giving an error.

The best would be to start opening the helpfile for the functions / actions you lijke to do and looking at the examples. :)

Jos 


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

I really don't know much about scripts so thanks for the pointers.

I think I've managed to clean it up a bit but it still doesn't seem to be sending the keystroke.

RunWait ( @COMSPEC & " /c \\server\Shared\share\lm.bat", "\\server\Shared\share")
sleep (2000)
WinWaitActive("C:\Windows\System32\cmd.exe")
Send("{F3}")

 

Share this post


Link to post
Share on other sites

Looks much better ;)

Maybe it would be better to explain what it is you are trying to accomplish with the Batch file in stead of doing the keystrokes to a CMD window, as that is quite error prone.

Jos 


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

The batch file just opens up a dos application in cmd commands it to navigate to a menu

L:
CD \LM3
lr.exe lm3ied

Here the user is prompted to press F3 or Esc to run or exit.

I'd hoped to use AutoIT to select the window and send an F3 keystroke command.

Share this post


Link to post
Share on other sites

Try to Change @Comspec /c (close) to /k (keep open) then you can see how the CMD windows look like and check tittle and other info.

Like this:
 

RunWait ( @COMSPEC & " /k \\server\Shared\share\lm.bat", "\\server\Shared\share")
sleep (2000)
WinWaitActive("C:\Windows\System32\cmd.exe")
Send("{F3}")

Also notice that in my system Win7 x64 the tittle of cmd windows is:
"Administrator: C:\Windows\system32\cmd.exe"

Check your by running cmd and double check the Window Tittle...

Kind Regards
Alien.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now