Use a timer with the correct interval
Check the idle time
Refresh webpage if necessary
Then - the only way to reset the idle time programmatically is to simulate user activity
How to simulate user activity is your next task
That is why i recommended the mouse_event API

That are your exact steps to get your app running how you're expecting