I have for my Blender 2.8 addon 2 keyboard shortcuts that I add to the AddonPreferences:
In the init file I use this code to draw them:
class FC_AddonPreferences(AddonPreferences):
bl_idname = __name__
def draw(self, context):
layout = self.layout
col = layout.column()
kc = bpy.context.window_manager.keyconfigs.addon
for km, kmi in addon_keymaps:
km = km.active()
kmi.show_expanded = False
col.context_pointer_set("keymap", km)
rna_keymap_ui.draw_kmi([], kc, km, kmi, col, 0)
And here is how I add them
addon_keymaps = []
def register():
# add keymap entry
kcfg = bpy.context.window_manager.keyconfigs.addon
if kcfg:
km = kcfg.keymaps.new(name='3D View', space_type='VIEW_3D')
kmi = km.keymap_items.new("object.fc_immediate_mode_op", 'P', 'PRESS', shift=True, ctrl=True)
kmi_mnu = km.keymap_items.new("wm.call_menu", "Q", "PRESS", shift=True)
kmi_mnu.properties.name = FC_Main_Menu.bl_idname
kmi_mnu.active = True
addon_keymaps.append((km, kmi))
addon_keymaps.append((km, kmi_mnu))
This works, but when I save the settings and reopen Blender the changes that the user made are gone and reset to default.
What am I missing? Thx!