How to cancel OpenGL render by python In Blender

Hi Folks!
when I press Opengl Animation icon in Blender VSE it executes and if I press escape it interrupts.

in code:

bpy.ops.render.opengl(animation=True, sequencer=True)
It works to start the animation render, but how to interrupt it using escape key? Should KeyboardInterrupt function be attached with it?

Thanks in advance for your help!


Edit:: after some research: I have found modal can do this. But can’t figure out how to code this.