Use triggerhappy - https://github.com/wertarbyte/triggerhappy - it's already included in RasPI OS and you can just attach your PWM control scripts without having to deal with input processing.