Get Shortcut from keymaps

I try to make a script that render a shortcut chart in blender, but i cannot get a correct shortcut from keymap_items.

Where to find it?

import bpy

km = bpy.context.window_manager.keyconfigs.default.keymaps["3D View Tool: Move"]
print(km.name)
for i in km.keymap_items:
    print(i.name, i.ctrl, i.shift, i.alt, i.value, i.type)

Your code snippet worked for me. The console / terminal output:

3D View Tool: Move
Move False False False ANY EVT_TWEAK_L

What do you mean by “it” in this sentence?

I mean the key for “Move” as example,
i guessed keymap_items.value should give me the key to press, i expected “g”.
But it gives ANY. How i get the desired keystroke?

No, the .type attribute stores the key that is assigned. The .value attribute stores whether an event is triggered on PRESS or RELEASE. I think ANY means the event is triggered by both a key press and a key release.

For a different keymap example using Blender’s python console:

>>> kc = bpy.context.window_manager.keyconfigs
>>> km = kc.active.keymaps['Object Mode'].keymap_items['object.hide_view_set']
>>> km.type
'H'
>>> km.value
PRESS
1 Like