G+_Bob Samuelson Posted May 15, 2014 Share Posted May 15, 2014 Looking 4 a way to send a keyboard press to a specific window. Would be happy if I could just send it to the ACTIVE window. EXAMPLE .... send "e" to the open/active notepad program at 1 minute intervals. Link to comment Share on other sites More sharing options...
G+_Lee Crocker Posted May 15, 2014 Share Posted May 15, 2014 That's a totally OS- and desktop-specific thing to do, so there's certainly no way to do it with standard portable Python. Assuming you're talking about MS Windows, you might look into pywin32, pyHook, or similar add-on packages. Link to comment Share on other sites More sharing options...
G+_Darryl Medley Posted May 15, 2014 Share Posted May 15, 2014 This Web page shows one way to do it with Python although I haven't tried it myself: https://mail.python.org/pipermail/python-list/2011-April/600957.html Under MS Windows you send a WM_CHAR message to the target window. Link to comment Share on other sites More sharing options...
G+_Bob Samuelson Posted May 15, 2014 Author Share Posted May 15, 2014 Thanks for the link. Looks like what I was searching for. Portability not an issue and focused window only will work for my application...... EDITED 3:45 CDT .. does exactly what I was looking for. Thanks for the help! import win32com.client import win32api shell = win32com.client.Dispatch("WScript.Shell") shell.Run("notepad") # comment out if notepad is currently running. win32api.Sleep(100) shell.AppActivate("notepad") win32api.Sleep(100) shell.SendKeys("e") win32api.Sleep(3500) shell.SendKeys("e") win32api.Sleep(2500) Link to comment Share on other sites More sharing options...
Recommended Posts