user759885
user759885

Reputation:

How to capture keyboard input in Blender using Python

I am using blender 2.6 and I have written a script to do a common translation that I need for keyframing an animation. How can I trigger the function using a keyboard shortcut instead of repeatedly pressing a custom panel button?

I want something like onkeypress() but outside of the game engine.

It works in several directions so it would be useful to link to a combination of a button and an arrow key.

This is for aligning with background movie frames, frame by frame. So this is why I want a better solution than firing the scripts by clicking with the mouse.

Upvotes: 0

Views: 4247

Answers (1)

sambler
sambler

Reputation: 7079

To assign a keyboard shortcut try an example from the Manipulator Menu addon -

wm = bpy.context.window_manager
km = wm.keyconfigs.addon.keymaps.new(name='3D View Generic', space_type='VIEW_3D')
kmi = km.keymap_items.new('wm.call_menu', 'SPACE', 'PRESS', ctrl=True)
kmi.properties.name = "VIEW3D_MT_ManipulatorMenu"

If you truly want to capture keyboard input while your script is in control then look at the answer to This Question on blender.stackexchange

Upvotes: 1

Related Questions