# How to access the Kemap settings Preferences (Spacebar Action, Select Mouse button, etc) with python?

I use a python script to set up some startup preferences like this:

bpy.context.preferences.view.show_tooltips_python = True

However, there is a particular set of preferences I don't know how to access, the ones in the Keymap section where you specify what spacebar does, what mouse click you use to select, etc.

How can I access these settings?

Search the source

With Developer Extras turned on hover over the enum and choose edit source

This will open up (for me) scripts/keyconfigs/blender.py

    # General settings.
col = layout.column()
col.row().prop(self, "select_mouse", text="Select with Mouse Button", expand=True)
col.row().prop(self, "spacebar_action", text="Spacebar Action", expand=True)
if is_select_left:
col.row().prop(self, "gizmo_action", text="Activate Gizmo Event", expand=True)


Notice there is a generic property update method load(self, context)

def load():
from sys import platform
from bpy import context
from bl_keymap_utils.io import keyconfig_init_from_data

prefs = context.preferences
kc = context.window_manager.keyconfigs.new(IDNAME)
kc_prefs = kc.preferences


Ok then to the python console

>>> C.preferences.keymap.active_keyconfig
'blender'

>>> C.window_manager.keyconfigs['blender'].preferences['spacebar_action'] = 2


will set to the third option. The item that matches that number is available enum definition of the the Prefs class.

• For your other question re choosing keymap bpy.ops.preferences.keyconfig_import(filepath="pathto/keymap.py") Jun 28, 2020 at 6:05
• Thanks for both answers, I've used Edit Source before but a lot of what I see is beyond me. I don't think I would of found the answer without your help. Thanks for taking the time. Jun 28, 2020 at 6:06
• NP. Can be a tricky. There could be another way to get there, couldn't find it quickly. (some thing akin to ob.spacebar_action) Suggest look at bl_keymap_utils.io source Jun 28, 2020 at 6:09