如何跟踪或跟踪系统是否处于空闲状态 [英] How to trace or track system is idle status

查看:109
本文介绍了如何跟踪或跟踪系统是否处于空闲状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我们如何跟踪系统空闲状态.例如,在Windows屏幕保护程序中看到的屏幕保护程序会在系统闲置指定时间后启动,并且一旦我们移动鼠标或按键盘上的任意键,屏幕保护程序就会停止.

那么,如何跟踪该系统的空闲状态以及该空闲状态以来的持续时间,以及最终如何或何时退出该状态呢?

I want to know how can we track the system idle state. For example as seen in windows screensaver which starts when system is idle for specified time and as soon as we move mouse or press any key on keyboard the screensaver stops.

So how to trace that system idle state and also the duration since it is in that idle state and finally how or when it came out of that state?

推荐答案

两种检测屏幕保护程序是否处于活动状态的方法.
您可以调用SystemParametersInfo()
( http://msdn2.microsoft.com/en-us/library/ms724947.aspx [ ^ ])
传递SPI_GETSCREENSAVERRUNNING标志的API函数(例如,查看此示例:
( http://www.codeguru.com/forum/showthread.php?t=257949 [ ^ ])).您可以创建一个全局Windows消息挂钩,并拦截WM_SYSCOMMAND消息.找到此消息后,请检查wParam是否为SC_SCREENSAVE.与C/C ++相比,这在C#中更痛苦,但这绝对是可行的.有关更多信息,请查看以下内容:
( http://msdn.microsoft.com/library/default.asp?url =/archive/zh-cn/dnaraskdr/html/drgui48.asp [ http://www.codeproject.com/csharp/globalhook.asp [ ^ ])
并且此( http://www.codeguru.com/csharp/csharp/cs_syntax/anandctutorials/article.php/c5823/ [ ^ ])).


GL
There are two ways of detecting if a screensaver is active.
You can call the SystemParametersInfo()
(http://msdn2.microsoft.com/en-us/library/ms724947.aspx[^])
API function passing the SPI_GETSCREENSAVERRUNNING flag (for an example look at this:
(http://www.codeguru.com/forum/showthread.php?t=257949[^])). You can create a global Windows message hook, and intercept the WM_SYSCOMMAND message. When you find this message, check to see if wParam is SC_SCREENSAVE. This is a bit more of a pain in C# than C/C++, but it''s definitely doable. For more information have a look at this:
(http://msdn.microsoft.com/library/default.asp?url=/archive/en-us/dnaraskdr/html/drgui48.asp[^]).

I''d suggest you get used to Googling, as there''s already a stack of information out there for handling keyboard and mouse input in C#
(such as this (http://www.codeproject.com/csharp/globalhook.asp[^])
and this (http://www.codeguru.com/csharp/csharp/cs_syntax/anandctutorials/article.php/c5823/[^])).


GL


这篇关于如何跟踪或跟踪系统是否处于空闲状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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