Your question title is how to detect mouse inactivity. I've told you several times how to do that. Your OP says you want to prevent input after a certain amount of inactivity. That's a completely different question and there's no evidence in your code that shows you've made any progress with that.

So really, for anyone to help in any way, you need to bring us up to speed and explain which parts you have working and which parts you currently need help with.

I don't have a lot of time to spend helping with this, but someone else might be able to help...