Prompting user for input on locking screen
Keyboard Maestro.

What you want to achieve requires a daemon that runs in the background, launches with the system, and executes customized commands/scripts after detecting a trigger. It's no a small feat if you want to write one that has good stability.

Apart from the keys, Keyboard Maestro has triggers like Startup, System Wake, Login, While Logged In, etc. With some tweaking and compromise, this is the best shot I know.