I’m encountering an issue while developing a modal operator in Blender where the Middlemouse release event is never received. The operator detects the press event correctly but never gets the release event when I release the middle mouse button.
Here are the details:
Blender version: [4.2.1]
OS: [Windows 10]
Context: Running a modal operator in the 3D View
Expected behavior: The modal operator should receive both the Press and Release events for the Middlemouse.
Actual behavior: The modal operator receives the Press event but never the Release event for the middle mouse button
Below is code snippet of modal which only prints Press event
import bpy
class ModalMiddleMouseMoveOperator(bpy.types.Operator):
bl_idname = "wm.middle_mouse_move_modal"
bl_label = "Middle Mouse Move Modal Operator"
middle_held = False
def modal(self, context, event):
if event.type == 'ESC':
self.report({'INFO'}, "Cancelled")
return {'CANCELLED'}
# Track middle mouse press/release
if event.type == 'MIDDLEMOUSE':
if event.value == 'PRESS':
self.middle_held = True
print("Middle mouse pressed")
elif event.value == 'RELEASE':
self.middle_held = False
print("Middle mouse released")
# Track mouse move only if middle mouse is held
if event.type == 'MOUSEMOVE' and self.middle_held:
print(f"Mouse moved while middle held: {event.mouse_region_x}, {event.mouse_region_y}")
return {'PASS_THROUGH'}
def invoke(self, context, event):
context.window_manager.modal_handler_add(self)
print("Modal started. Press ESC to stop.")
return {'RUNNING_MODAL'}
def register():
bpy.utils.register_class(ModalMiddleMouseMoveOperator)
def unregister():
bpy.utils.unregister_class(ModalMiddleMouseMoveOperator)
if __name__ == "__main__":
register()
bpy.ops.wm.middle_mouse_move_modal('INVOKE_DEFAULT')
```