How to obtain the idle time of users' mouse and keyboard in Windows

Source: Internet
Author: User

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}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.