I’ve been writing my first add-on, and whilst it works, I had to add my keyboard shortcut to the “Window” keymap, when ideally, it would be in the “Dopesheet” keymap.
So after asking for help here, and also reading this, I started testing around to find out which keymaps let me set shortcuts and which don’t.
I used this example of the add-on tutorial, with the only difference being that I changed the execute function to be just this:
def execute(self, context):
print('hello, world')
return {'FINISHED'}
Then went about replacing “Object Mode” on line 40, by different keymaps name to see which ones work and which don’t:
km = wm.keyconfigs.addon.keymaps.new(name='Object Mode', space_type='EMPTY')
Here’s what I worked out so far. The followings are the ones that add items to their keymaps, followed by where the shortcut works:
- Window - works everywhere
- Frames - works everywhere you can change frame with the arrow (so not in the outliner)
- Animation - works in all the panels listed under Animation in the Editor Type selector
- Object Mode - works in 3d view in object mode, but as one would expect, not in edit mode
- Grease Pencil - works like Object Mode, but funnily enough, also in edit mode.
And these do not add any item to their keymaps:
- Dopesheet
- 3D View
- Outliner
- Text
- Console
- Property Editor
- Sequencer
- Image
- and more…
So my question is: Is there any logic to this or is it random?