How do I send keystrokes to a console window in Windows XP?
zxymike93 at gmail.com
zxymike93 at gmail.com
Mon Jan 8 21:06:15 EST 2018
在 2005年7月16日星期六 UTC+8下午8:46:34,Benji York写道:
> GoogleGroups at 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
Recently, I tried `.AppActivate("Command Prompt")` but cannot catch the `cmd` on my Windows 7, the result is `False`. I know it has been some years since your reply, and the name of the window object may be different.(Still I'm pretty thankful to your answer.) Just wondering if there is a similar solution with another object name.
More information about the Python-list
mailing list