How to fake keyboard input with Python
Does anyone know if it is possible to have a Python script running in the background tha开发者_如何学Pythont can enter keyboard input into the app in the foreground. Maybe a python library that someone knows about. I'm wanting to fake my Mac's keyboard input in order to automate a very specific task.
It's probably easiest (but non-portable - this would be mac only) to use appscript. That is, of course, assuming that either the app you want to control supports applescript, or you have another tool which can type/click that can be controlled via applescript (ala Quickeys).
Use Appscript plus GUI scripting. I have lots of Python scripts at my blog that demonstrate this. Here's one:
http://www.libertypages.com/clarktech/?p=2413
GUI scripting allows you to script applications that don't fully support Applescript. Here's a guide for the Applescript version of that. Appscript basically lets you do what Applescript does only in native Python.
http://www.macosxautomation.com/applescript/uiscripting/index.html
精彩评论