0
$\begingroup$

example of multiple keybinds of the same identifier

I found this working code to enable/disable keybinds:

wm = bpy.context.window_manager
wm.keyconfigs.default.keymaps['3D View'].keymap_items['view3d.move'].active = False

But it disables the first keybind it finds instead of all which have view3d.move assigned to them.

To disable all of them I thought about running something like:

wm = bpy.context.window_manager
keys = wm.keyconfigs.default.keymaps['3D View'].keymap_items['view3d.move']

for key in keys:
    key.active = False

But got an error TypeError: 'KeyMapItem' object is not iterable. I'm still new to Python.

$\endgroup$

1 Answer 1

1
$\begingroup$

keymap_items is a list that has implemented an iterator over its member's idname. It is possible to have multiple entries in a list with the same value. Your line

keys = wm.keyconfigs.default.keymaps['3D View'].keymap_items['view3d.move']

returns only the first value.

One way to find all of the keys that have an idname of "'view3d.move'" is to use a list comprehension, like this one:

key_list = [key for key in bpy.context.window_manager.keyconfigs.default.keymaps['3D View'].keymap_items if key.idname == 'view3d.move']

The above code says to create a list consisting of all of the keys in the 3D View keymaps that have an idname of view3d.move That will create a list that you can iterate over:

for key in key_list:
    key.active = False
$\endgroup$
2
  • $\begingroup$ Confirming it works perfectly. Thank you for teaching me :) $\endgroup$
    – AlexM
    Commented May 14, 2022 at 8:17
  • $\begingroup$ @AlexM you're welcome. $\endgroup$ Commented May 14, 2022 at 13:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .