I noticed that when Blender writes out a custom keymap it completely overrides all keys that were assigned previously. I don't want to miss out on any changes in the default key mappings in future versions of blender, so I am trying to make a script that would append the keys I want to use to the defaults.
Here is the script:
import bpy
import os
wm = bpy.context.window_manager
kc = wm.keyconfigs.user
km = kc.keymaps['View2D']
kmi = km.keymap_items.new('view2d.zoom', 'BUTTON4MOUSE', 'PRESS')
kmi = km.keymap_items.new('view2d.zoom', 'BUTTON4MOUSE', 'PRESS', shift=True)
kmi = km.keymap_items.new('view2d.pan', 'BUTTON5MOUSE', 'PRESS')
km = kc.keymaps['View2D Buttons List']
kmi = km.keymap_items.new('view2d.scroller_activate', 'BUTTON4MOUSE', 'PRESS')
kmi = km.keymap_items.new('view2d.pan', 'BUTTON5MOUSE', 'PRESS')
kmi = km.keymap_items.new('view2d.zoom', 'BUTTON4MOUSE', 'PRESS', shift=True)
km = kc.keymaps['3D View']
kmi = km.keymap_items.new('view3d.rotate', 'BUTTON4MOUSE', 'PRESS')
kmi = km.keymap_items.new('view3d.move', 'BUTTON5MOUSE', 'PRESS')
kmi = km.keymap_items.new('view3d.zoom', 'BUTTON4MOUSE', 'PRESS', shift=True, ctrl=True)
kmi = km.keymap_items.new('view3d.dolly', 'BUTTON4MOUSE', 'PRESS', shift=True)
km = kc.keymaps['View3D Fly Modal']
kmi = km.keymap_items.new_modal('PAN_ENABLE', 'BUTTON5MOUSE', 'PRESS', any=True)
kmi = km.keymap_items.new_modal('PAN_DISABLE', 'BUTTON5MOUSE', 'RELEASE', any=True)
km = kc.keymaps['View3D Rotate Modal']
kmi = km.keymap_items.new_modal('CONFIRM', 'BUTTON4MOUSE', 'RELEASE', any=True)
km = kc.keymaps['View3D Move Modal']
kmi = km.keymap_items.new_modal('CONFIRM', 'BUTTON5MOUSE', 'RELEASE', any=True)
km = kc.keymaps['View3D Zoom Modal']
kmi = km.keymap_items.new_modal('CONFIRM', 'BUTTON4MOUSE', 'RELEASE', any=True)
km = kc.keymaps['View3D Dolly Modal']
kmi = km.keymap_items.new_modal('CONFIRM', 'BUTTON4MOUSE', 'RELEASE', any=True)
km = kc.keymaps['Image']
kmi = km.keymap_items.new('image.view_pan', 'BUTTON4MOUSE', 'PRESS')
kmi = km.keymap_items.new('image.view_pan', 'BUTTON5MOUSE', 'PRESS')
kmi = km.keymap_items.new('image.view_zoom', 'BUTTON4MOUSE', 'PRESS', shift=True)
km = kc.keymaps['Node Editor']
kmi = km.keymap_items.new('node.backimage_move', 'BUTTON5MOUSE', 'PRESS', alt=True)
km = kc.keymaps['Clip Editor']
kmi = km.keymap_items.new('clip.view_pan', 'BUTTON4MOUSE', 'PRESS')
kmi = km.keymap_items.new('clip.view_pan', 'BUTTON5MOUSE', 'PRESS', ctrl=True)
kmi = km.keymap_items.new('clip.view_zoom', 'BUTTON4MOUSE', 'PRESS', shift=True)
It works when I manually execute after blender has started, but I tried putting the script in my scripts/startup user folder and it said View2D was not found. So it's executing before View2D keymap context is defined, but I don't know how to make the script execute after everything else has been mapped. Any ideas how to make this work?