检测用户不活动(系统范围内) [英] Detect user inactivity (systemwide)

查看:76
本文介绍了检测用户不活动(系统范围内)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



有没有一种(简单的)方法来检测整个系统的用户不活动状态?就像屏幕保护程序一样?

我知道GetLastInputInfo,这似乎正是我在寻找的东西,但不幸的是,它不是系统范围的,而仅适用于当前进程.

我想编写一个密码管理器(KeePass)的扩展程序,该扩展程序在特定数量的用户不活动后锁定密码文件...

谢谢.

此致

Hi,

Is there a (simple) way to detect user inactivity system wide? As a screensaver would do?

I know GetLastInputInfo, this seems to be exactly what I am looking for but unfortunately it is not system wide but only for the current process.

I want to write an extension for a password manager (KeePass) which locks the password file after a specific amount of user inactivity...

Thank you.

Regards,

推荐答案

<pre><br />
Imports System.Runtime.InteropServices<br />
<br />
Public Class IdleTime<br />
<br />
    Private Declare Function GetLastInputInfo Lib "User32.dll" _<br />
      (ByRef lastInput As LASTINPUTINFO) As Boolean<br />
<br />
    <structlayout(layoutkind.sequential)> _<br />
    Public Structure LASTINPUTINFO<br />
        Public cbSize As Int32<br />
        Public dwTime As Int32<br />
    End Structure<br />
<br />
<br />
    Public ReadOnly Property IdleTime() As Integer<br />
<br />
        Get<br />
<br />
            Dim lastInput As New LASTINPUTINFO<br />
<br />
            lastInput.cbSize = Marshal.SizeOf(lastInput)<br />
<br />
            If GetLastInputInfo(lastInput) Then<br />
<br />
                Return (Environment.TickCount - lastInput.dwTime) / 1000<br />
<br />
            End If<br />
<br />
        End Get<br />
<br />
    End Property<br />
<br />
End Class<br />
</pre>




谢谢,但是GetLastInputInfo()不会影响当前的应用程序吗?

此功能对于输入空闲检测很有用.但是,GetLastInputInfo不会在所有正在运行的会话中提供系统范围的用户输入信息.而是,GetLastInputInfo仅为调用该函数的会话提供特定于会话的用户输入信息.

实际上,我的应用程序是一个托盘应用程序,因此它不会一直从用户那里获取任何输入,因此该解决方案应该适用于整个系统,而不仅仅是该应用程序.

Hi,

Thank you, but doesn''t GetLastInputInfo() affect the current application?

This function is useful for input idle detection. However, GetLastInputInfo does not provide system-wide user input information across all running sessions. Rather, GetLastInputInfo provides session-specific user input information for only the session that invoked the function.


In fact my application is a tray application so it will not get any input from the user all the time so the solution should work for the whole system, not just the application.

Regards,


关于,您没有提到要使用哪种语言,但是这里有一篇不错的C#文章:

如何在C#中使用和不使用平台调用来检查用户是否不活动 [
You didn''t mention which language you want to do this in, but here''s a nice C# article about this:

How to check for user inactivity with and without platform invokes in C#[^]


这篇关于检测用户不活动(系统范围内)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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