Vizible’s Blog

Python – Simulate key press using WSH COM

Posted in Programming, Python by wearetherock on July 31, 2009

Use win32api and win32com under ActivePython 2.6.2
~

import win32api
import win32com.client

shell = win32com.client.Dispatch("WScript.Shell")
shell.Run("calc")
win32api.Sleep(100)
shell.AppActivate("Calculator")
win32api.Sleep(1000)
shell.SendKeys("1{+}2{+}3{+}4=")

~
Reference http://code.activestate.com/recipes/65107/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: