0

我的应用程序应该在电脑锁定之前发出警告。它使用一个计时器,设置为 x 秒(x = 计算机因不活动而锁定之前的时间)。我使用以下代码来检测鼠标和键盘活动:

    Private Declare Function GetLastInputInfo Lib "user32.dll" (ByRef inputStructure As inputInfo) As Boolean
Private Structure inputInfo
    Dim structSize As Int32
    Dim tickCount As Int32
End Structure

Private info As inputInfo
Dim lastTick As Int32
Dim firsttick As Int32


   Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
    'The size of the structure for the API call.
    info.structSize = Len(info)
    '
    'Call the API.
    GetLastInputInfo(info)
    '
    'Compare the tickcount values to determine if activity has occurred or not.
    If firstTick <> info.tickCount Then
        firsttick = info.tickCount
        count = 15
        Me.WindowState = FormWindowState.Minimized
        Me.Visible = False
    End If

End Sub

计数由计时器 1 确定,计时器 1 的间隔为一秒。如果用户与键盘或鼠标交互,则计数将重置为 x 秒(在此示例中,出于测试目的,它是 15 秒;每次我想测试应用程序时,我都懒得等待实际时间)。以上所有方法都很完美,直到我想到了视频播放。如果您没有注意到,在 YouTube 或 WMP...等上播放视频可以防止 PC 锁定/休眠。

我的问题很简单......如何检测视频是否正在播放并将计数重置为 x。一个更好的问题是:我怎样才能检测到计算机锁定多长时间,所以我什至不需要计数或检测用户活动?

4

0 回答 0