473,394 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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.

Jul 21 '05 #1
6 3274
Go**********@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
Jul 21 '05 #2
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.)

Jul 21 '05 #3
Go**********@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
Jul 21 '05 #4
RTG
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.

Jul 21 '05 #5
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
Jul 21 '05 #6
RTG
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

Jul 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Olli Piepponen | last post by:
Hi, I'm having a little problem catching keystrokes under Windows. I did a little research and found that with mscvrt.getch() one can cath a single key that is pressed. However this doesn't work...
2
by: Boba | last post by:
Hi, I'm programming a WinForm application. I would like to enter commands that will send output that will help me to locate bugs in the future. I know that there is a way to send output by...
5
by: Go Perl | last post by:
Hello Here is an interesting question which I could not solve it. I have an old dos app for which source code is lost. I just have the exe file. So I have created a front-end for that. I...
1
by: Mészáros Tamás | last post by:
Hi, How can I "steal" selection from an application? e.g. I select some text in the browser and I would like to see this text from my application. Can I send for example CTRL-C (Clipboard-Copy)...
5
by: Lucas Tam | last post by:
Hi all, Has anyone done this before? Send client side keystrokes to an application from a webpapge? This maybe more of a Javascript question. In short, I have an application on the client's...
6
by: Gary | last post by:
Hi, I am trying to use the "System.Windows.Forms.SendKeys" class for triggering the Ctrl+P key. Syntax: System.Windows.Forms.SendKeys.Send("^(P)") This is not working ..what could be the...
1
by: Max | last post by:
Hi, I am trying to paste text in a console window using SendKeys and the Clipboard (I am using Windows XP SP2 and .NET 1.1). Here is the code (I have a form with two edit boxes, DosTitle in...
1
by: Joey | last post by:
I am using the below code to run a dos based program. While it is running you can hit ctrl-c to cancel the process. Does anyone know how I can send the same keystroke to the already runing...
0
by: neonspark | last post by:
I'm buidling some simple macro functionality for my app so the users can record a sequence of keyboard inputs and replay them reliably via some menu. Originally, I used: protected override bool...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.