On msdn, there is already a magic system function getlastinputinfo to get the user's last input (mouse or keyboard) time.
PS: vs2005 is available on msdn, and vc6 is low. This system function is not available. In addition, it is clearly indicated that the system that supports this function is only Windows 2000 (in fact, all versions of the NT kernel should support the system, and I have passed the win 7 test ).
The prototype is as follows:
Bool getlastinputinfo (plastinputinfo plii );
The usage is as follows:
1/* Get user mouse and keyboard idle time 2*3 * success return non-negative integer, indicating the number of milliseconds the user is idle 4 * failure return negative integer 5 */6 int countuseridletime (void) 7 {8 lastinputinfo Info; 9 info. cbsize = sizeof (lastinputinfo); 10 if (! Getlastinputinfo (& info) 11 return-1; 12 13 DWORD idle_time = gettickcount ()-info. dwtime; 14 return (INT) idle_time; 15}