Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   How do I send keystrokes to a console window in Windows XP? (http://www.velocityreviews.com/forums/t347102-how-do-i-send-keystrokes-to-a-console-window-in-windows-xp.html)

GoogleGroups@garringer.net 07-14-2005 05:22 PM

How do I send keystrokes to a console window in Windows XP?
 
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.


Benji York 07-16-2005 12:46 PM

Re: How do I send keystrokes to a console window in Windows XP?
 
GoogleGroups@garringer.net 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

GoogleGroups@garringer.net 07-18-2005 06:56 PM

Re: How do I send keystrokes to a console window in Windows XP?
 
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.)


Benji York 07-19-2005 02:47 AM

Re: How do I send keystrokes to a console window in Windows XP?
 
GoogleGroups@garringer.net 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



RTG 07-19-2005 02:47 PM

Re: How do I send keystrokes to a console window in Windows XP?
 
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.


Peter Hansen 07-20-2005 01:50 AM

Re: How do I send keystrokes to a console window in Windows XP?
 
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

RTG 07-20-2005 01:53 PM

Re: How do I send keystrokes to a console window in Windows XP?
 
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



All times are GMT. The time now is 10:45 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.