1
$\begingroup$

Is there a way to get the complex label that Blender shows for keymap items, when the only thing I have is the key type for that keymap?
That is, getting the "Spacebar" string, when all you have is "SPACE" (like from the event.type in a modal handler of a modal operator)?

enter image description here

$\endgroup$

1 Answer 1

1
$\begingroup$

Yes, you can get the same displayable key name.
You need to use that "SPACE" string (AKA the event type, which can be anything from the event type constants), as a key in the dictionary of enum items of the EnumProperty type of the bl_rna of the bpy.types.Event struct (phew!).

The path to this dictionary is:

bpy.types.Event.bl_rna.properties['type'].enum_items

To be accessed like this from Python (usually inside the modal() function of your operator, but not necessarily):

>>> eventType = event.type # This is a string. It can be 'SPACE', 'LEFTMOUSE' etc.
>>> enumItem = bpy.types.Event.bl_rna.properties['type'].enum_items[eventType]
>>> enumItem.name # The displayable key name.
'Spacebar'
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .