Hey fellow Windows users
I have an example of how to simulate keystrokes in Blender for utilizing hotkeys, or whatever the hell you want to use them for!
You’ll NEED to download the latest Windows API python extensions by Mark Hammond from here: http://starship.python.net/crew/mhammond/downloads/win32all-144.exe
While win32api and win32gui are both included with python 2.0.1, they have been updated since then to include more api calls- including the keybd_event call.
The interface is a little whacky (ok a lot)… You can’t run the script by pressing Alt-P because your cursor needs to be in the 3D window for the hotkeys to be read properly. So I’ve put it OnFrameChanged. This also means it runs when you load blender also… Read update below!
I’ve included a list of hotkeys and their corrosponding codes (which aren’t ASCII or scancode oddly, but rather a windows-specific set). I still need to find out how to use key modifiers like Ctrl and Alt, but I know it’s possible… I accessed CTRL-TAB a few times, so I know it’s possible. Something to do with the second variable that’s passed to the keybd_event, but they’re not true scan codes so…
To show you that this can operate outside of Blender, when you start the blend file it will open up notepad through the start menu and scream. You’ll understand when you see it.
Just get it now!
Using the win32api and win32gui you can access other things besides keystroke simulation- like video, sound, all sorts of window handles and the like. Just don’t use this for anything malacious from within Blender, please!!!
Example file in a .zip:
This one opens up notepad and types a message upon framechanged
This one automatically subdivide-smooths an object from outside of edit mode
I’m trying to find a way of positioning the cursor manually into the 3D window through the API so you can actually run the code by pressing Alt-P.
You can set the mouse cursor by using
using 100 for both x and y generally puts the cursor in the 3D window, but it’s not assured.