2.9: the art of keyboard shortcuts

Hi all :slight_smile:

As an answer to some of my needs for speed and fluent workflow i often asked myself how to use the right-click on UI elements for making a shortcut on it and what is the method to set up variables/classes names for various action ( set, toggle, switch between 2 values or more, etc… )

Here’s my real case:
I want PGUP key to toggle between Material and Texture in this window:

If i R-click on a button i can add a shortcut but it will ask me to choose between all the values and this is not what i want.

If i look at shortcuts list in preferences windows, here’s what i got:

But from here i really d’ont know what to do and what to type in for the toggling feature i want.

Could anyone please help me ?

Thanks and happy blending !

That’s because you’ve set the hotkey to a menu, any command with “wrm.context” calls a menu. Try to set the hotkey as follows:


In this case, F2 toggles between solid and wireframe shading.

1 Like

Hi @Hologram

Thanks for you answer.
However this is not exactly what i need.

i discovered that the button i want to activate with my shortcut is part of View3DShading class, on color_type member.

However, when i write View3DShading.color_type in the field you stroke, i got no type submenu :frowning:

@pitibonom sorry, I hadn’t read the entire post carefully. If you add a shortcut to the material button, by right clicking, you’ll get a pop-up menu in which you can choose whether you want the colour to be based on the material or texture. Right-clicking the menu items individually allows you to set your hotkey. Mind you, you won’t be able to toggle between the two. That will have to be achieved with a script/ addon of some sort.

Replace wm.context_menu_enum by wm.context_toggle_enum
Reset same Context Attribute.
Set MATERIAL and TEXTURE as values.

This looks pretty close to what i need but for some reason it do no work :frowning:

I got this:

Is there something i missed @zeauro ? :slight_smile:

i got it :smiley:

Context Attributes had not to be reset but had to contain the attribute given when you choose to add a shortcut on a button.
The 2 values possible are okay.

I wonder whether there could be a 3rd value for not toggling but cycling through those values ?

Thanks a lot and happy blending !

partly answering to myself:

There is a wm.context_cycle_enum… but it seems it can only take all the enums from the context attribute control and it cannot choose between for example MATERIAL,RANDOM and TEXTURE :confused:

Yeah, for that (i.e. custom enum) you’d have to code your own operator. Keymaps are not that flexible, unfortunately.

Wow, that’s all super-intimidating.

Is there a good resource for this topic? As soon as I see something like “wm.context_cycle_enum” my brain freezes.

1 Like

Well, there’s the API documentation. I would’t call that “good” though by any stretch of imagination, even if you’re routinely coding operators. The documentation is… lacking there, severely.

Thanks, Stan. ::weeping::

LOL !!! :joy:

Even with the API doc i confess i’m lost. I think my brain is far from frosen ! kinda melt…

@Stan_Pancakes sorry mate but i sincerely feel allergicto all blender API doc :confused:
I wish one day doc makers take example on more user friendly docs of other tools :wink:
And to be honest i’d really be more than glad to contribute :stuck_out_tongue:

Happy blending !

Interesting, I wasn’t aware about these toggle options. Do you by any chance know whether these are applicable to non-viewport related commands?
Shade smooth/ sharp is one such command for which such a use comes to mind.

No, Shade Smooth and Shade Flat are their own operators (different in object and edit modes), not UI items that you could toggle like this.