How to check if there is no interaction with screen by user

I want to test if device is idle. For example no interaction with device for next 5 minutes
and in that case we want to trigger a function say startbreak();

How i can do it; Which plugin and function i need to use;

Can any one create a hello world for this?