1
$\begingroup$

So recently I have been trying to create an addon for the video sequencer so that I can automate some of the common tasks I do. One of the operators I plan to make requires the mouse to be over the sequencer preview so that it's position can be used. However I can not get a keymap to work in the sequencer preview. To test if this was a problem with the function I made an empty operator with and invoke function to create a pop up when it was called. Even then the keymap for it did not work when I tried it with the preview window. Due to this I believe the problem is probably with the keymap creation but I could be wrong. This is my code for creating the keymap:

wm = bpy.context.window_manager
km = wm.keyconfigs.addon.keymaps.new(name='Preview', space_type='SEQUENCE_EDITOR', region_type='PREVIEW')
kmi = km.keymap_items.new(customOperator.bl_idname, type='J', value='PRESS', shift=True)

I have used this key combo before for testing and so I don't believe the problem with it. Additionally I have tried changing the space_type and region_type with no luck. Any help would be appreciated.

I have been referencing this page of the documentation while trying to figure out the problem.

$\endgroup$

1 Answer 1

1
$\begingroup$

I recommend use the py console to figure out the arguments based on the default config:

>>> C.window_manager.keyconfigs['Blender'].keymaps['Sequencer 
                                                              Common']
                                                             Preview']
>>> C.window_manager.keyconfigs['Blender'].keymaps['SequencerPreview'].space_type
'SEQUENCE_EDITOR'

Just pass name='SequencerPreview' and space_type='SEQUENCE_EDITOR' to keymaps.new(), and the registration works as expected. CtrlY-demo based on our famous Operator Simple template that comes with Blender:

import bpy

class SimpleOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "sequencer.simple_operator"
    bl_label = "Simple Image Operator"

    def execute(self, context):
        print(SimpleOperator.bl_idname, "has been called")
        return {'FINISHED'}

addon_keymaps = []
def register():
    bpy.utils.register_class(SimpleOperator)
    addon_keymaps.clear()

    wm = bpy.context.window_manager # handle the keymap
    kc = wm.keyconfigs.addon
    if kc:
        km = wm.keyconfigs.addon.keymaps.new(
            name='SequencerPreview', space_type='SEQUENCE_EDITOR')
        kmi = km.keymap_items.new(
            SimpleOperator.bl_idname, type='Y', value='PRESS', ctrl=True)
        addon_keymaps.append((km, kmi))

def unregister():
    bpy.utils.unregister_class(SimpleOperator)
    for km, kmi in addon_keymaps:
        km.keymap_items.remove(kmi)
    addon_keymaps.clear()

if __name__ == "__main__":
    register()

Related: Create keyboard shortcut for an operator using python?

$\endgroup$
1
  • 1
    $\begingroup$ thank you that has fixed it $\endgroup$ Commented Sep 14, 2021 at 15:18

You must log in to answer this question.

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