Create keyboard shortcut for an operator using python?
Minimal add-on example using keymap_items.new() to register a new hotkey CtrlW in 3d View:
import bpy

bl_info = {
    &quot;name&quot;: &quot;Your Addon Name&quot;,
    &quot;author&quot;: &quot;Author Name&quot;,
    &quot;version&quot;: (0, 1),
    &quot;blender&quot; : (2, 80, 0),
    &quot;location&quot;: &quot;&quot;,
    &quot;warning&quot;: &quot;&quot;,
    &quot;wiki_url&quot;: &quot;&quot;,
    &quot;tracker_url&quot;: &quot;&quot;,
    &quot;category&quot;: &quot;&quot;
}


class OBJECT_OT_CustomOp(bpy.types.Operator):
    &quot;&quot;&quot;Tooltip&quot;&quot;&quot;
    bl_idname = &quot;object.simple_operator&quot;
    bl_label = &quot;Simple Object Operator&quot;

    def execute(self, context):
        print (self.bl_idname)
        return {'FINISHED'}


addon_keymaps = []

def register():
    bpy.utils.register_class(OBJECT_OT_CustomOp)
    
    # Add the hotkey
    wm = bpy.context.window_manager
    kc = wm.keyconfigs.addon
    if kc:
        km = wm.keyconfigs.addon.keymaps.new(name='3D View', space_type='VIEW_3D')
        kmi = km.keymap_items.new(OBJECT_OT_CustomOp.bl_idname, type='W', value='PRESS', ctrl=True)
        addon_keymaps.append((km, kmi))


def unregister():
    bpy.utils.unregister_class(OBJECT_OT_CustomOp)
    
    # Remove the hotkey
    for km, kmi in addon_keymaps:
        km.keymap_items.remove(kmi)
    addon_keymaps.clear()


if __name__ == &quot;__main__&quot;:
    register()

    # test call
    #bpy.ops.object.simple_operator()