如何确定在没有用户活动的情况下经过了指定时间 [英] How to determine a specified time has elapsed without user activity

查看:77
本文介绍了如何确定在没有用户活动的情况下经过了指定时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能确定用户在特定时间段内没有活动,例如屏幕保护程序????

Is is possible to determine user has no activity for a specific time in windows, like screen savers do ????

推荐答案

您需要捕获所有输入系统级事件.这是使用Windows Hooks完成的.从这里开始:
http://msdn.microsoft.com/zh-我们/library/windows/desktop/ms632589%28v=vs.85%29.aspx [ http://msdn.microsoft.com/zh-我们/library/windows/desktop/ms682396%28v=vs.85%29.aspx [ http://msdn.microsoft.com/zh-我们/library/windows/desktop/ms682400%28v=vs.85%29.aspx [ http://msdn.microsoft.com/zh-我们/library/windows/desktop/ms686211%28v=vs.85%29.aspx [ http://msdn.microsoft.com/zh-我们/library/windows/desktop/ms685081%28v=vs.85%29.aspx [ http://msdn.microsoft.com/zh-我们/library/windows/desktop/ms687032%28v=vs.85%29.aspx [ http://msdn .microsoft.com/en-us/library/windows/desktop/ms682655%28v = vs.85%29.aspx [
You need to catch all input events on a system-wide level. This is done using Windows Hooks. Start here:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms632589%28v=vs.85%29.aspx[^].

You can only install the global (system-global hook) in a DLL using SetWindowsHookEx. The code of the hook should communicate with the host application. You should understand that the hook handler code does not have to belong to your thread or process, so you should use some inter-process communication to access event data.

As far as I understand your problem, I would use global named event objects. You only need to wait for some first input event. You can create some thread in the host application and put it to wait state by the call to WaitForSignleObject on the handle of the event object. The OS will switch the calling thread off and won''t schedule it back to execution until it is waken up by the signaled event. Signal the same event in your hooked event handler. The thread will wake up and do some action which you should call in the next line.

Please see:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682396%28v=vs.85%29.aspx[^],
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682400%28v=vs.85%29.aspx[^],
http://msdn.microsoft.com/en-us/library/windows/desktop/ms686211%28v=vs.85%29.aspx[^],
http://msdn.microsoft.com/en-us/library/windows/desktop/ms685081%28v=vs.85%29.aspx[^],
http://msdn.microsoft.com/en-us/library/windows/desktop/ms687032%28v=vs.85%29.aspx[^].

See the article referenced in the last link (for example) for other synchronization primitives.

Read the event object and overview: http://msdn.microsoft.com/en-us/library/windows/desktop/ms682655%28v=vs.85%29.aspx[^].

—SA


我认为您应该使用GetLastInputInf(...)方法.请看下面的链接:

http://msdn.microsoft.com/zh-CN /library/windows/desktop/ms646302(v=vs.85).aspx [
I think you should use GetLastInputInf(...) method. Look at the link below:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms646302(v=vs.85).aspx[^]

Hope this solved your issue


这篇关于如何确定在没有用户活动的情况下经过了指定时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆