I want to capture the system idle time. Means if the user did not press any key or did not move the mouse then it is considered as system idle time. I want the code for this in C or C++ on windows operating system. Please help me. It's urgent....

Thanks & Regards
Mohit Malhotra

11 Years
Discussion Span
Last Post by Salem

There are probably a number of ways to solve that. The solution I took was to create another listener thread. The main program thread sends a message to this listerner thread every keyboard and mouse event. The listner thread waiks up from Sleep() every minute and checks its input queue. If nothing then it knows there has been no keyboard or mouse activity during the last minute and can take appropriate actions.

You might also use SetTimer() and and capture WM_TIMER events. The os will call a function of your choice after the specified amount of time has elapsed. The main program could have a counter that increments each time a keyboard or mouse event occurs, then the timer function just checks that counter -- if counter is zero then there were no events.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.