GG is not actually a keybinding, G starts the grab operator and that reacts on certain keytrokes while it's running modally. It uses a modal map (keymapping) for this ability.
You can edit modal maps in User preferences > Input, but not call arbitrary operators (in fact, only sub-operations defined by the operator in C, like Select or Deselect in Border Select op).
For python-scripted operators, there's an event
argument passed to modal()
and you can check for keystrokes (event.type
, event.value
etc.) and react in whatever way.
Detect G keystroke in a modal operator:
import bpy
from bpy.props import IntProperty, FloatProperty
class ModalOperator(bpy.types.Operator):
"""Move an object with the mouse, example"""
bl_idname = "object.modal_operator"
bl_label = "Simple Modal Operator"
first_mouse_x = IntProperty()
first_value = FloatProperty()
def modal(self, context, event):
if event.type == 'MOUSEMOVE':
delta = self.first_mouse_x - event.mouse_x
context.object.location.x = self.first_value + delta * 0.01
elif event.type == 'G':
self.report({'INFO'}, "G")
context.object.location.x = self.first_value
return {'CANCELLED'}
elif event.type == 'LEFTMOUSE':
return {'FINISHED'}
elif event.type in {'RIGHTMOUSE', 'ESC'}:
context.object.location.x = self.first_value
return {'CANCELLED'}
return {'RUNNING_MODAL'}
def invoke(self, context, event):
if context.object:
self.first_mouse_x = event.mouse_x
self.first_value = context.object.location.x
context.window_manager.modal_handler_add(self)
return {'RUNNING_MODAL'}
else:
self.report({'WARNING'}, "No active object, could not finish")
return {'CANCELLED'}
def register():
bpy.utils.register_class(ModalOperator)
def unregister():
bpy.utils.unregister_class(ModalOperator)
if __name__ == "__main__":
register()
Transform Modal Map - what (sub-)operations a possible during the modally running operators:
