osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


? 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.