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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.