Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How do I send keystrokes to a console window in Windows XP?

Reply
Thread Tools

How do I send keystrokes to a console window in Windows XP?

 
 
GoogleGroups@garringer.net
Guest
Posts: n/a
 
      07-14-2005
How do I use Python to send keystrokes to a console window in Windows
XP?
Or perhaps there is an application that I can call to do this?

Thank you for your help.

 
Reply With Quote
 
 
 
 
Benji York
Guest
Posts: n/a
 
      07-16-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> How do I use Python to send keystrokes to a console window in Windows
> XP?


import win32com.client

shell = win32com.client.Dispatch("WScript.Shell")
shell.AppActivate("Command Prompt")

shell.SendKeys("cls{ENTER}")
shell.SendKeys("dir{ENTER}")
shell.SendKeys("echo Hi There{ENTER}")
--
Benji York
 
Reply With Quote
 
 
 
 
GoogleGroups@garringer.net
Guest
Posts: n/a
 
      07-18-2005
Thank you, Benji.

This gives me hope, but what I really need to do is to send keystrokes
to an <<<already existing>>> console window.

Any help there?

(P.S. Sorry that I wasn't more specific.)

 
Reply With Quote
 
Benji York
Guest
Posts: n/a
 
      07-19-2005
(E-Mail Removed) wrote:
> This gives me hope, but what I really need to do is to send keystrokes
> to an <<<already existing>>> console window.


That's exactly what the code does. Try it out, you'll see how it works
quickly enough.
--
Benji York


 
Reply With Quote
 
RTG
Guest
Posts: n/a
 
      07-19-2005
Benji,

This appears to be exactly what we need.
I also see that by changing "Command Prompt" to "Notepad" or another
application, the key strokes are sent there.

With this capability, other possibilities open up.
Is there a way to read the output from the from the console window?
For example, how can we capture the output of the dir command?

Thank you for your help.

 
Reply With Quote
 
Peter Hansen
Guest
Posts: n/a
 
      07-20-2005
RTG wrote:
> With this capability, other possibilities open up.
> Is there a way to read the output from the from the console window?
> For example, how can we capture the output of the dir command?


Normally one does that using a call to things like os.popen, or using
the new subprocess module.

If that's not suitable (if for some bizarre reason you really do want to
pick up the output of "dir" after someone has run it manually in the
console, and I can't imagine why you would want that), then search in
the list archives for a recent thread that did investigate just that
issue: how to capture text from a console window in Win32. I don't
recall the answer but I'm sure you can find it.

-Peter
 
Reply With Quote
 
RTG
Guest
Posts: n/a
 
      07-20-2005
Thank you, Peter.

The application is a <<<continuously running interactive program>>> and
we want to automatically interact with it (e.g. sendkeys and capture
certain text responses).

I will look for the thread you mentioned.

- Roy

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Send keystrokes to Firefox or Safari? Stedwick Ruby 8 12-25-2008 12:30 PM
USB device that can send keystrokes? Saqib Ali Computer Security 6 10-30-2008 05:52 PM
Trying to send keystrokes to NES emulator srinathava@gmail.com Python 0 12-01-2006 02:41 AM
Send Keystrokes to Client Side Application Lucas Tam ASP .Net 5 12-02-2004 07:19 PM



Advertisments