Linking a script to the Sculpt tools

Lately I have been working on writing a script that will maintain the ‘resolution’ of a mesh by selectively subdividing regions that contain large sized faces. I am curious, is there any way I can somehow link this script to the sculpt tools in blender, such that for every stroke in sculpt mode, the script will update the mesh?