Modal Operate does not register Mouse Release

I have a simple Modal Operator based on one of the Coding examples. It registers when a mouse button was pressed and when it was released. It is basically working but the release is not being registered once during the mouse is down any in blender property has changed or basically “something is happening”. For instance you move an object or change any value or open a context list.

The modal is not being terminated but it seems like its being overriden by something else. Is the any way to make this work?

Code:

import bpy

class ModalX(bpy.types.Operator):
    bl_idname = "wm.modalx"
    bl_label = "Modal X"

    def modal(self, context, event):
        
        if event.type in {'LEFTMOUSE', 'RIGHTMOUSE'}:
            if event.value == 'PRESS':
                print('Pressed')
            elif event.value == 'RELEASE':
                print('Released')

        if event.type == 'ESC':
            self.cancel(context)
            print ('cancelled')
            return {'CANCELLED'}

        return {'PASS_THROUGH'}

    def execute(self, context):
        wm = context.window_manager
        wm.modal_handler_add(self)
        return {'RUNNING_MODAL'}

    def cancel(self, context):
        wm = context.window_manager

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


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


if __name__ == "__main__":
    register()

    bpy.ops.wm.modalx()

1 Like

Hi man,

The mouse event will be “absorbed” by a lot of things,
the overlay buttons, the panels buttons and property,
Any Toolbar tool…
Basically anything that do something?

I asked something similar some time ago, didnt really find an answer, only workaround

Unreal4 have the option to make the event be absorbed - consumed ,
so when a certain type of event is called you can choose if reach all your blueprint or not.
Maybe something in blender exist, but i dont know

1 Like

Thanks a lot for your reply. Yes indeed meanwhile I found a workaround too.

Instead I am using “mouse move” event to recognize if the change that I am trying to catch has happened.
I want the script to recognize if a specific “transform” event has been done by the user. And luckily this is always automatically being written into the “info” panel of Blender. So my solution is to read the info panel of blender each time the mouse moves after mousedown. When something was written to the panel then this can be treated as mouse release aswell. So the event listener is being terminated after mouse release OR the info panel has a new line.

Thats a really hacky solution but its the only one I can think of and its actually working pretty smooth. :+1: :slight_smile: