I think I found a way.
It doesnât block key inputs, so would have to rework the code I was already using in modal(), but I believe this method DOES get the event+info that I needed from it.
The gist of it is to call a mostly blank operator using (âINVOKE_DEFAULTâ) then get/store data from that.
Normally when you call an operator using python, it implies (âEXEC_DEFAULTâ) , and only default to invoke when you click it via UI button.
"Properties"
import bpy
global_event = None
global_timer = 0
"Operators"
class ADDITIVE_OT_Get_Event(bpy.types.Operator):
bl_description = "Get Event data accessible via operators, and store as a global/local variable"
bl_idname = 'wm.get_event'
bl_label = "Get Event info"
bl_options = {'INTERNAL',}
bl_undo_group = ""
@classmethod
def poll(cls, context):
return True
def invoke(self, context, event):
global global_event
bpy.event = global_event = event
# The bpy part gives a value you can read in console, or even other scripts
# (Note: displays the last event logged, so there's a delay if trying to manually check for yourself)
# To use elsewhere, use something like this:
if (hasattr(bpy, 'event')):
...
# Or you can just use this:
# global_event = event
return {'FINISHED'}
def execute(self, context):
self.report({'INFO'}, "Error: use bpy.ops.wm.get_event('INVOKE_DEFAULT') to function correctly")
return {'PASS_THROUGH'}
class ADDITIVE_OT_operations:
# I put theses defs in classes now, for sorting in Notepad++
@bpy.app.handlers.persistent
def Add_Constant(self):
def update_timer(max=220):
global global_timer
# Display timer value, to measure how slow you want it's delay
def sec(timer):
return round(timer/max*60)
if sec(global_timer) in range(0, max, 5):
print('Timer: ', sec(global_timer))
# Comment out this section to stop spamming the console
global_timer += 1
if (global_timer > max):
global_timer = 0
bpy.ops.wm.get_event('INVOKE_DEFAULT')
return global_timer
global global_event
event = global_event
timer = update_timer(220)
if event:
if event.alt:
print('Alt derp')
...
else:
This will spam for a second or two, on startup
print("No event")
...
# This def is used to load the event on startup.
# You can't run the op during register() because reasons
@bpy.app.handlers.persistent
def Add_Reload(self):
bpy.ops.wm.get_event('INVOKE_DEFAULT')
"Registration"
def register():
if (__name__ == "__main__" or not __package__):
bpy.utils.register_module(__name__)
bpy.app.handlers.scene_update_post.append(ADDITIVE_OT_operations.Add_Constant)
bpy.app.handlers.load_post.append(ADDITIVE_OT_operations.Add_Reload)
def unregister():
bpy.app.handlers.scene_update_post.remove(ADDITIVE_OT_operations.Add_Constant)
bpy.app.handlers.load_post.remove(ADDITIVE_OT_operations.Add_Reload)
if (__name__ == "__main__" or not __package__):
bpy.utils.unregister_module(__name__)
if (__name__ == "__main__"):
register()
To be clear, the reason for the timer is because scene update. where my main thing occurs, will try to run several times and run the operator continuously, resulting in a crash.
So, I opt to using a timer that convinces it to slow itâs roll.
Heh, this can also be tweaked a little to solve my first problem, because this can be used to get an updated context, to read the area/space for the mouse.