2
$\begingroup$

I want to print the hotkeys for some tools in the console. How can I retreive the hotkey for let's say the circle select tool, or the hotkey for rotating the viewport with python?

Note that I do not want to execute those tools. So I guess I need to access the keymap directly, and read the hotkeys from there. But how does it work?

$\endgroup$

1 Answer 1

3
$\begingroup$

You need to have some clue about how each command is executed (i.e. the operator) in order to find its hotkeys, but if you do, it's not too difficult:

wm            = bpy.context.window_manager                       # Blender window manager
keymaps_3DV   = wm.keyconfigs['Blender'].keymaps['3D View']      # 3D View hotkeys
circle_keymap = keymaps_3DV.keymap_items['view3d.select_circle'] # Circle select keymap object
main_key      = circle_keymap.type                               # "C" in this case

If you want to see if any modifier key is used, or if the ALT / SHIFT / CTRL keys are used, you can access this info this way:

modifier_key = circle_keymap.key_modifier   # Is 'NONE' in this case
shift        = circle_keymap.shift          # Is False in this case
ctrl         = circle_keymap.ctrl           # Is False in this case
alt          = circle_keymap.alt            # You've guessed it

There's lots of other interesting properties of hotkeys to investigate, but I'll leave it to you.

To see the rotate operator's hotkey, access it thus:

circle_keymap = keymaps_3DV.keymap_items['transform.rotate']
$\endgroup$
4
  • $\begingroup$ Thanks a bunch. I think this gives me the needed kickstart :) $\endgroup$
    – Tiles
    Jan 2, 2016 at 11:47
  • $\begingroup$ @Tiles, had some errors in the code above (wrote this too fast and too early in the morning lol). Have another look at the code if you had trouble earlier. $\endgroup$
    – TLousky
    Jan 2, 2016 at 15:29
  • $\begingroup$ Mornings are evil! :D Thanks for your effort. Mh, to retreive the key somehow works. But it seems that it gets a hardcoded hotkey from somewhere. I have changed the hotkey for Circle select to L, but it still shows C. The hotkey for rotate shows correct though. Interesting results ^^ $\endgroup$
    – Tiles
    Jan 2, 2016 at 17:23
  • 1
    $\begingroup$ The solution is to use wm.keyconfigs['Blender User'] and wm.keyconfigs['Blender Addon'] instead of wm.keyconfigs['Blender']. Then i get the actual hotkeys. Problem solved. Thanks for help and listening :) $\endgroup$
    – Tiles
    Jan 4, 2016 at 7:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.