Can't get a keymap (adding a keyboard shortcut inside a script) to work

Hi,

I tried to add a keymap to an operator on a script I’m writing, and it just won’t work.

Here’s an example script that can be installed as an addon to test this, and see how I tried:
http://pastebin.com/6aX9Pd85

If anyone has any experience with this and know what I’m doing wrong, I’d be grateful for any help.

Here’s the code simply pasted here as well:

bl_info = {
    "name"        : "Test",
    "author"      : "Me",
    "blender"     : (2, 70, 0),
    "version"     : (0, 0, 0, 1),
    "location"    : "3D View > Toolbox",
    "description" : "Test",
    "category"    : "Object"
}


import bpy


class test( bpy.types.Panel ):
    bl_idname      = "teststuff"
    bl_label       = ""
    bl_category    = "Test"
    bl_space_type  = 'VIEW_3D'
    bl_region_type = 'TOOLS'


    @classmethod
    def poll( self, context ): return True


    def draw( self, context):
        layout = self.layout
        col    = layout.column()


        col.operator('object.myop')
        
class myop( bpy.types.Operator ):
    bl_idname      = "object.myop"
    bl_label       = "Test"
    bl_description = "Test"
    bl_options     = {'REGISTER', 'UNDO'}


    mode = bpy.props.StringProperty()


    @classmethod
    def poll( self, context ): return True


    def execute( self, context ):
        if self.mode == 'A':
            print( "Got A" )
        else:
            print( "Got Else" )
            
        return {'FINISHED'}
            
# store keymaps here to access after registration
addon_keymaps = []


def register():
    bpy.utils.register_module(__name__)


    # add keymap entry
    km = bpy.context.window_manager.keyconfigs.addon.keymaps.new(
        name = 'Test', space_type = 'EMPTY'
    )


    kmi = km.keymap_items.new(
        "object.myop", 'ACCENT_GRAVE', 'PRESS', alt = True
    )


    kmi.properties.mode = 'A'


    addon_keymaps.append((km, kmi))


def unregister():
    bpy.utils.unregister_module(__name__)


    # remove keymap entry
    for km, kmi in addon_keymaps:
        km.keymap_items.remove(kmi)


    addon_keymaps.clear()

So, still no progress. Help? :slight_smile: