Access Blender's hotkeys!!! Windows only :(

Hey fellow Windows users :slight_smile:

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
http://www.fireengine51.org/blender/sendkeys.zip
This one automatically subdivide-smooths an object from outside of edit mode
http://www.fireengine51.org/blender/simulate3.zip

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.

edit:
You can set the mouse cursor by using

win32api.SetCursorPos([x,y])

using 100 for both x and y generally puts the cursor in the 3D window, but it’s not assured.

And to ChrisGarret, when I have access to the Alt key, this will do exactly what you want-> saving out a VRML file at each frame in an animation.

wow!

you’re intense man.

thanks!

Ok I realize my last demo sucked… This time I’ll demonstrate something usefull in blender. You can use this script to automatically smooth subdivide a mesh. It will also bring up the appropriate buttons for the currently selected object type.

You can download the script here:
http://www.fireengine51.org/blender/simulate3.zip

Have fun!

That looks really cool, and should solve my problem. I am currently trying to get the VRML 2 export script to work, but without much success.

Thanks

Chris