Cannot get keymap for IMAGE_EDITOR to work

I am trying to create a keymap to scale the selected verts in the UV Editor to zero in the X direction. The code below works correctly in the UV Editor with F3 and find operator "Scale UV selected verts to X=0"

So that's all good.

When I bind a keymap to the space_type 'IMAGE_EDITOR', it shows up as registered in PREFS, but does not execute when I press Shift+Ctrl+X. What am I doing wrong? FWIW, I've tried numerous different key combinations with no success. Thanks for any help.

import bpy

# SCALE X IN UV EDITOR
class OBJECT_OT_scale_xuv(bpy.types.Operator):
"""scales VERTS to x=0"""
bl_idname = "object.vertscale_xuv"
bl_label = "Scale UV selected verts to X=0"

def execute(self, context):

bpy.ops.transform.resize(value=(0, 1, 1), orient_type='VIEW', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)),
orient_matrix_type='VIEW', constraint_axis=(True, False, False),
mirror=True, use_proportional_edit=False, proportional_edit_falloff='SMOOTH',
proportional_size=1, use_proportional_connected=False, use_proportional_projected=False)

return {'FINISHED'}

def registerKeymaps():
wm = bpy.context.window_manager

# KEY SHORTCUTS FOR SPACE TYPE IMAGE_EDITOR
km_uv = wm.keyconfigs.addon.keymaps.new(name='Image Editor Tool: Uv, Scale', space_type='IMAGE_EDITOR')

## SCALE UV VERTS X
km_uv_i = km_uv.keymap_items.new('object.vertscale_xuv', 'X', 'PRESS', shift=True, ctrl=True)

def unregisterKeymaps():
km.keymap_items.remove(kmi)

def register():
bpy.utils.register_class(OBJECT_OT_scale_xuv)
registerKeymaps()

def unregister():
unregisterKeymaps()
bpy.utils.unregister_class(OBJECT_OT_scale_xuv)

if __name__ == "__main__":
register()

• AFAIK the name has to match the area for whatever reason. Setting the name to 'Image' works, see: pasteall.org/dXT0/raw. However I'd expect 'UV Editor' to work as well which doesn't. Not sure why, need to investigate. Aug 18, 2021 at 14:29
• Well, FWIW, that was the fix. Not sure why 'Image' works and nothing else does. Thanks SO MUCH for your help!!! How can I mark your solution as Answered? Aug 18, 2021 at 21:49
• @brockmann Could you add that as an answer? Sep 9, 2021 at 13:12

Pass 'Image' as the name and 'IMAGE_EDITOR' as space_type to keymaps.new(), and the registration works as expected. CtrlY demo based on the Operator Simple template:

import bpy

class SimpleOperator(bpy.types.Operator):
"""Tooltip"""
bl_idname = "image.simple_operator"
bl_label = "Simple Image Operator"

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

def register():
bpy.utils.register_class(SimpleOperator)

wm = bpy.context.window_manager # handle the keymap
if kc:
kmi = km.keymap_items.new(
SimpleOperator.bl_idname, type='Y', value='PRESS', ctrl=True)

def unregister():
bpy.utils.unregister_class(SimpleOperator)

km.keymap_items.remove(kmi)

if __name__ == "__main__":
register()


If you would like to limit the hotkey to only work when editing UV's, just add a poll method to your operator asking for an active UV map or whether there is an image loaded at all:

    @classmethod
def poll(cls, context):
sima = context.space_data
return sima.show_uvedit and sima.image is None

• Cool, is there an exhaustive list for the names? Right now I'm just looking at the keymap titles in the UI Preferences Sep 9, 2021 at 14:22
• To place in UV Editor keymaps km = wm.keyconfigs.addon.keymaps.new(name='UV Editor', space_type='EMPTY') Sep 9, 2021 at 15:46
• Thanks @batFINGER, Mystery, when passing UV Editor and EMPTY the hotkey does not register properly... also tried to pass Window, no luck. Sep 10, 2021 at 8:56
• Not that I know of, I always use the console and shimmy through the default hotkeys @Leander Sep 10, 2021 at 8:59