I haven't used it, but from a quick skim, it sounds like input-remapper can do this.
https://github.com/sezanzeb/input-remapper/blob/main/readme/macros.md
hold
Runs the child macro repeatedly as long as the input is pressed.
Examples:
hold(key(space))
https://github.com/sezanzeb/input-remapper/blob/main/readme/examples.md
key(BTN_LEFT) a single mouse-click