Context Dependent Hotkeys?

How to have a single hotkey do multiple things based upon the selection? I can’t figure out if it’s possible in Blender. Here is an example with the hotkey d:
Object selected : Center Pivot
Polygon selected : Extrude Face
Edge selected : Extend Edge
Vert selected : Bevel Vert

Often a single hotkey will do something different when 1 edge is selected, vs 2 edges, vs an edge loop. I’m switching over from other software so I apologize if I’m mixing up terms.

Do you want to make a addon/hack or just customize your keybindings? If it’s an addon you can probably get away with checking the context on execute. If you’re just doing vanilla… then it might be trickier since the priorities for each keymap tend to overlap on a more broad scale (telling you by experience, I’m not sure about the actual mechanics)

If you want fine-precision, best way to go is crafting it yourself in a script. Let me know if you need a hand with it! I love doing workflow hacks :slight_smile:

Hello, thank you for your response. I’m looking for a script to assign to a hotkey. I’m just grasping at the basics of Blender so if I’m approaching this wrong let me know. In Modo I would write a script like this and assign it to a single hotkey. (This is just a portion of it.):


vert = lx.eval('select.typeFrom vertex;edge;polygon;item ?')
edge = lx.eval('select.typeFrom edge;vertex;polygon;item ?')
polygon = lx.eval('select.typeFrom polygon;edge;vertex;item ?')

if vert == 1:
	vC = lx.eval('select.count vertex ?')
	if vC == 2:
		lx.eval('tool.set mesh.topology on snap:true')
elif edge == 1:
	#test for boundary edge to run windowpane script.
	edges = lx.evalN('query layerservice edges ? selected')
	selectedLayer = lx.eval('query layerservice layers ? selected')
	eC = lx.eval('select.count edge ?')

Any template or direction toward other scripts like this would be appreciated as I have had a hard time finding that info on my own.

this is done in much the same way in Blender, only with operators. check out the simple operator template that ships with Blender and it will probably make more sense- but the basic idea would be that you use the same type of context sensitivity logic that you just described. If the selection mode is edge, do this, if vert, do that, etc.