How to use python to check one variable in preferences

Hello there. I am attempting to script my first addon. I am familiar with Python and very familiar with Blender but I am having a lot of difficulty wrapping my head around this seemingly novice issue.

Goal: All I want is a script that can go into Blender’s user preferences>input and check “emulate 3 button mouse”. In other words, I just want the script to change the value from false to true.

I have been reading Blender documentation and watching youtube tutorials on scripting for Blender, but I can’t quite wrap my head around the difference between context, types, data, and operators.

I’m not sure. To even access the “emulate 3 button mouse” boolean would I need to use:

Here is my code:

this is what I get from the console:
AttributeError: expected Operator, make3butts class to have an “bl_lable” attribute

I’m sure my code is completely faulty I just don’t know where to start. Any suggestions would be of great help. Thanks

Sometimes you can investigate how the UI is built and gain lots of information. You can right click on the item you want and then click on [edit source].

# flip the checkbox
import bpy
inputs = bpy.context.preferences.inputs
inputs.use_mouse_emulate_3_button = not inputs.use_mouse_emulate_3_button

Thank you! I used this information to build a panel for myself that lets me control this variable from the tools side-bar:

Really cool. :slight_smile: