My suggestion would be a continuous timer every x minutes. In the timer function you can use GetLastInputInfo(...) or CGEventSourceCounterForEventType check whether it is due or not.
If you want it more exact you may calculate the
timepoint of the last user input + x minutes - now
which is the duration for the next timer event. Or if (timepoint of the last user input + x minutes) is less than now it is due.
the OS tracks this, somehow, somewhere. there is probably a way to ask for it. Which may be what you are showing, but I don't know how to use it... All modern OS track this to log you out after a bit or fire up a screen saver or whatever.