Key Shortcut [ like Grease Pencil ] for 2 registered classes

Hello, i’m trying to put together a shortcut for the dynotopo collapse edges mode /subdivide mode.

you know how Grease pencil activates only when you hold D down? ( D + Left mouse )
I want to do something similar with the Q key and this.

Problem:
if I let go of the Q key while holding down the left mouse, it doesn’t toggle back, (and kindof breaks it a bit)
-any suggestions so it performs similar to the grease pencil toggle?

it’s registering 2 methods - collapse mode when Q is pressed, subdiv when Q is released
here’s the shortcut:

bl_info = {
    "name": "ShortcutTool",
    "author": "Robert Fornof",
    "version": (0, 1),
    "blender": (2, 70, 0),
    "location": "Check the shortcuts for dynamic topology ",
    "description": "Q toggles subdiv edges and collapse edges",
    "warning": "",
    "wiki_url": "",
    "category": "Object"}
import bpy
from bpy.app.handlers import persistent




def Press(self,context):
    c = 'COLLAPSE'
    context.tool_settings.sculpt.detail_refine_method = c
    print("Pressed")
    
def Release(self,context):
    s = 'SUBDIVIDE'
    c = 'COLLAPSE'
    context.tool_settings.sculpt.detail_refine_method = s
    print("Released")
   
def Toggle(self,context):
    s = 'SUBDIVIDE'
    c = 'COLLAPSE'
    context = bpy.context.scene
    currentSetting = context.tool_settings.sculpt.detail_refine_method
    if currentSetting == s:
        context.tool_settings.sculpt.detail_refine_method = c
        
    elif currentSetting == c:
        context.tool_settings.sculpt.detail_refine_method = s


    else:
        context.tool_settings.sculpt.detail_refine_method = s #default




class TopoShortcutOn(bpy.types.Operator):
    """This Operator Add a Object to Another with Boolean Operations"""
    bl_idname = "object.collapseon"
    bl_label = "Topo Subdiv Toggle"


    @classmethod
    def poll(cls, context):
        return context.active_object is not None
    
    def execute(self, context):
        print("Toggled")
        Release(self,context)
        
        return {'FINISHED'}


class TopoShortcutOff(bpy.types.Operator):
    """This Operator Add a Object to Another with Boolean Operations"""
    bl_idname = "object.collapseoff"
    bl_label = "Topo Subdiv Toggle"


    @classmethod
    def poll(cls, context):
        return context.active_object is not None
    
    def execute(self, context):
        print("off")
        Press(self,context)
        
        return {'FINISHED'}
    
    


def setTool(input):
    context.tool_settings.sculpt.detail_refine_method = input
 
 #------------------- REGISTER ------------------------------      
addon_keymaps = []


def register():


    bpy.utils.register_class(TopoShortcutOff)
    bpy.utils.register_class(TopoShortcutOn)
    km = bpy.context.window_manager.keyconfigs.active.keymaps['Sculpt']
    kmi = km.keymap_items.new(TopoShortcutOff.bl_idname, 'Q', 'PRESS', ctrl = False)
    kmi = km.keymap_items.new(TopoShortcutOn.bl_idname, 'Q', 'RELEASE', ctrl = False)
    


def unregister():
    
    bpy.utils.unregister_class(TopoShortcutOff)
    bpy.utils.unregister_class(TopoShortcutOn)
    for km, kmi in addon_keymaps:
        km.keymap_items.remove(kmi)
    addon_keymaps.clear()
    


if __name__ == "__main__":
    register()



https://github.com/fornof/BlenderAddons/blob/master/TopoShortcutBind.py

create a keymap item with .map_type “MOUSE”, .type “LEFT_MOUSE” (left press) and .key_modifier “Q”

(you can check the Grease Pencil key binding)

the operator needs to have an invoke() method which adds a modal handler, so modal() is used to handle the live events, you can try that out with the Operator Modal template.