Enabling and disabling hotkeys in Blender using the Python API

Using hotkeys is one of the most advanced features in Blender to seriously increase your work speed. We can easily control the availability of a particular keyboard shortcut using the Blender Python API.

All available keyboard shortcuts are grouped in Blender into sections – KeyMap.

All existing keymaps can be accessed through the Python API as follows:

A specific set of hotkeys can be accessed by index or by name:

Inside the section, all keyboard shortcuts are stored in the “keymap_items” list. Each individual keyboard shortcut is stored in a “KeyMapItem” object. We can access it by index or by “idname” identifier:

To turn the current keyboard shortcut on or off, use the “active” property:

By setting the “active” value to True or False, we can turn the current keyboard shortcut on or off.

For example, let’s turn off the “shift + a” key combination, which is responsible for opening the menu for adding objects in the 3D viewport area. The “KeyMapItem” element itself can most easily be found by the name of the section “Object Mode” and the name of the keyboard shortcut “Add”:

Disabling:

Now, when we press “shift + a” short code in the 3D viewport area, the “Add” menu does not appear.

And turning it back on:

The menu now works as before.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments