【问题标题】:Monitor user activity in vb.net监控 vb.net 中的用户活动
【发布时间】:2016-07-13 08:12:05
【问题描述】:

我想制作一个监控用户活动的程序。我不需要知道用户在做什么,我只需要知道他在做什么。移动鼠标或打字。该程序将用于向公司展示谁在办公桌前以及谁离开了工作站。因此,如果 2 分钟内没有任何活动,则表示用户已离开计算机。

我正在考虑使用键盘挂钩和鼠标位置来监控每 5 秒的变化。在每次更改时,我都会重置计数器。

有没有更好的方法? (例如阅读屏保倒计时之类的)

【问题讨论】:

  • @BanForFun 询问Have you tried something 然后发布答案的目的是什么? OP 显然没有尝试过,并且通过发布代码并不能真正帮助 OP。我们不是编码服务,而是帮助解决特定问题和/或有问题的代码问题;目前没有。

标签: vb.net monitoring


【解决方案1】:

您可以 P/Invoke WinAPI 的 GetLastInputInfo() 函数,以便能够获取收到最后一个输入的毫秒计数自计算机启动后

用上面的值减去Environment.TickCount 将得到自收到最后一个输入以来已经经过了多少毫秒

<DllImport("user32.dll")> _
Public Shared Function GetLastInputInfo(ByRef plii As LASTINPUTINFO) As Boolean
End Function

<StructLayout(LayoutKind.Sequential)> _
Public Structure LASTINPUTINFO
    <MarshalAs(UnmanagedType.U4)> _
    Public cbSize As Integer
    <MarshalAs(UnmanagedType.U4)> _
    Public dwTime As Integer
End Structure

Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
    Dim LastInput As New LASTINPUTINFO With {.cbSize = Marshal.SizeOf(GetType(LASTINPUTINFO))} 'The "cbSize" field must be set every time we call the function.
    If GetLastInputInfo(LastInput) = True AndAlso _
        (Environment.TickCount - LastInput.dwTime) >= 120000 Then '120000 ms = 120 s = 2 min.

        Timer1.Stop()
        'Computer has been idle for 2 minutes. Do your stuff here.
    End If
End Sub

这将检查鼠标和键盘输入。

Timer 的Interval 属性设置为5000,使其每5 秒检查一次,Enabled 属性设置为True

请记住,如果要再次检查,必须在两分钟的空闲时间过去后重新启动计时器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多