here the smallest bit of code to show what I mean.
import bpy
from bpy.props import IntProperty
class ModalOperator(bpy.types.Operator):
"""Move an object with the mouse, example"""
bl_idname = "object.modal_test_operator"
bl_label = "AA Run"
modal_counter = IntProperty(default=0)
def modal(self, context, event):
if (event.type == 'MINUS') and (event.value == 'RELEASE'):
self.modal_counter += 1
print('triggered!', self.modal_counter)
elif event.type == 'LEFTMOUSE':
print('ended by finish')
return {'FINISHED'}
elif event.type in {'RIGHTMOUSE', 'ESC'}:
print('ended by cancel')
return {'CANCELLED'}
return {'RUNNING_MODAL'}
def invoke(self, context, event):
self.modal_counter = 0
print('start')
context.window_manager.modal_handler_add(self)
return {'RUNNING_MODAL'}
def register():
bpy.utils.register_class(ModalOperator)
def unregister():
bpy.utils.unregister_class(ModalOperator)
if __name__ == "__main__":
register()
The output of this operator when you press the Minus key twice is this:
start
triggered! 1 <-- first press
triggered! 2 <-- first press
triggered! 3 <-- second press
triggered! 4 <-- second press
ended by finish
What am I doing wrong? If i set it to listen for event.value == 'PRESS'
it's OK, but it seems 'RELEASE'
is triggered twice?