I’ve made a user-modifiable keymap menu with a more concise source code, so share it.
There is no need to specify the key map name or registration location in the menu.
Keys that match add-on keymaps registered in the “addon_keymaps” list,
Search from the key map settings of Blender and display.
The key map registration location is also displayed.
# Search for keymap items in the addon's keymap list (addon_keymaps) from within Blender settings and display the menu
import rna_keymap_ui
box = layout.box()
col = box.column()
col.label(text="Keymap List:",icon="KEYINGSET")
wm = bpy.context.window_manager
kc = wm.keyconfigs.user
old_km_name = ""
get_kmi_l = []
for km_add, kmi_add in addon_keymaps:
for km_con in kc.keymaps:
if km_add.name == km_con.name:
km = km_con
break
for kmi_con in km.keymap_items:
if kmi_add.idname == kmi_con.idname:
if kmi_add.name == kmi_con.name:
get_kmi_l.append((km,kmi_con))
get_kmi_l = sorted(set(get_kmi_l), key=get_kmi_l.index)
for km, kmi in get_kmi_l:
if not km.name == old_km_name:
col.label(text=str(km.name),icon="DOT")
col.context_pointer_set("keymap", km)
rna_keymap_ui.draw_kmi([], kc, km, kmi, col, 0)
col.separator()
old_km_name = km.name