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


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:

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'

    def poll( self, context ): return True

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

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

    mode = bpy.props.StringProperty()

    def poll( self, context ): return True

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

def register():

    # add keymap entry
    km =
        name = 'Test', space_type = 'EMPTY'

    kmi =
        "object.myop", 'ACCENT_GRAVE', 'PRESS', alt = True
    ) = 'A'

    addon_keymaps.append((km, kmi))

def unregister():

    # remove keymap entry
    for km, kmi in addon_keymaps:


So, still no progress. Help? :slight_smile: