Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
dump all keymap bindings for blender 2.65. the word 'key' here is in the colloquial sense as there are keyboard, mouse, and other map binding types. it's really an event dispatch mapping that happens to cover keyboards and other sources.
#there may be a better way to find keybindings but until I do, this will have to suffice...
#likewise, until i figure out blender addons proper, this will need to be pasted to the python console
import operator
import bpy
import os
wm=bpy.context.window_manager
kmlut={
'active':{True:'=',False:' '},
'ctrl':{True:'^',False:' '},
'alt':{True:'@',False:' '},
'shift':{True:'#',False:' '},
'any':{True:'*',False:' '},
}
def kmixlat(km,mod):
return kmlut[mod][getattr(km,mod)]
#Xref: http://www.blender.org/documentation/blender_python_api_2_65_release/bpy.types.KeyMapItem.html
fkm=[]
fkwidth=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
for context,kmMap in wm.keyconfigs.default.keymaps.items():
for kmItem in kmMap.keymap_items:
t=[context,' ',
kmItem.map_type,' ',
kmixlat(kmItem,'active'),
kmixlat(kmItem,'ctrl'),
kmixlat(kmItem,'alt'),
kmixlat(kmItem,'shift'),
kmixlat(kmItem,'any'),' ',
kmItem.value,' ',
kmItem.type,' ',
kmItem.name,' ',
kmItem.idname]
for i,ignore in enumerate(t):
if(len(t[i])>fkwidth[i]):
fkwidth[i]=len(t[i])
fkm.append(t)
fksort=sorted(fkm,key=operator.itemgetter(0,2,10,12))
#field order:
# menucontext eventorigin flags eventtype bindkey description python-method
#
# flags are in order (a space in that column means doesnt apply or inactive)
# '=' : active binding (' ' means inactive)
# '^' : needs meta control key pressed as well
# '@' : needs meta alt key pressed as well
# '#' : needs meta shift key pressed as well
# '*' : needs any meta key pressed
#change this save location to suit your needs:
with open('{0}{1}'.format(os.path.sep,os.path.join('tmp','blender-keymap.txt')),'w') as mapfile:
for binding in fksort:
k=''
for c,ignore in enumerate(binding):
k+='{0:{width}}'.format(binding[c],width=fkwidth[c])
print(k,sep='',file=mapfile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.