0
$\begingroup$

I'm making an addon that has some remapping of the key configurations.

How would you guys edit the transform modal map trough code?

I want Y axis to be overriden by Space and ⇧ Shift + Space

These are the specific keys that I want to override:

enter image description here

def add_keymap_items(clear_existing=True):
    if clear_existing:
        clear_keymaps()

    wm = bpy.context.window_manager
    kc = wm.keyconfigs.addon
    if kc:  
        
        # Handling modal keymap changes
        km_transform_modal = kc.keymaps.get('Transform Modal Map')
        if km_transform_modal:
            # Add a modal keymap item for Y axis constraint during translation
            kmi = km_transform_modal.keymap_items.new_modal('CONFIRM', 'SPACE', 'PRESS')
            kmi_props = kmi.properties
            kmi_props.name = 'axis_y'
            addon_keymaps.append((km_transform_modal, kmi))
        else:
            print("Modal keymap 'Transform Modal Map' not found")

        km_edit_mode = kc.keymaps.new(name='Mesh', space_type='EMPTY')
        # LOOP CUT
        kmi = km_edit_mode.keymap_items.new(HP_OT_loopcut.bl_idname, type='R', value='PRESS', ctrl=True, shift=False)
        addon_keymaps.append((km_edit_mode, kmi))

        # SMART PUSH AND SLIDE
        kmi = km_edit_mode.keymap_items.new(HP_OT_PushAndSlide.bl_idname, type='G', value='PRESS', ctrl=False, shift=True)
        addon_keymaps.append((km_edit_mode, kmi))

        kmi = km_edit_mode.keymap_items.new('mesh.select_prev_item', type='WHEELOUTMOUSE', value='PRESS', ctrl=False, shift=True)
        addon_keymaps.append((km_edit_mode, kmi))

        kmi = km_edit_mode.keymap_items.new('mesh.select_next_item', type='WHEELINMOUSE', value='PRESS', ctrl=False, shift=True)
        addon_keymaps.append((km_edit_mode, kmi))
        
        kmi = km_edit_mode.keymap_items.new('mesh.loop_select', type='LEFTMOUSE', value='PRESS', ctrl=False, shift=False, alt=True)
        addon_keymaps.append((km_edit_mode, kmi))
        
        kmi = km_edit_mode.keymap_items.new('mesh.edgering_select', type='LEFTMOUSE', value='DOUBLE_CLICK', ctrl=False, shift=False, alt=True)
        addon_keymaps.append((km_edit_mode, kmi))
$\endgroup$
1
  • $\begingroup$ Hello and welcome. Please use a title that matches the content of the post. It should read like a question, be descriptive but succinct, unique and identifying, summarizing the problem so that anyone searching for similar issues is likely to find this. Remove anything superfluous, avoid using words like "this", "help with", "issue" or "question about", instead describe what "it" is. Remember, your title is the first thing visitors see, answers you get depend heavily on it. See What is the problem of asking “How do I do this?" $\endgroup$ Commented May 20 at 8:20

1 Answer 1

1
$\begingroup$

Builtin modal keymaps cannot be modified by addons, the user must modify them themselves through the UI. This is by design since it is not supported because it is not the intended use of addon keymaps.

This is stated by developer Campbell Barton in a bug report about similar attempt.

Addons can only declare modal keymaps for its own declared modal operators.

One possible solution (which I never tested personally) is to include your own modal operator and modify its keymap instead. Depending on what it does, this operator could simply call existing operators to recreate their functionality.

$\endgroup$

You must log in to answer this question.

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