注册 登录
编程论坛 VB.NET论坛

(求助)如何获取鼠标键盘闲置时间?

zxdw520 发布于 2011-03-19 20:27, 1281 次点击
我都研究了一天了查了很多的资料,还是没能搞定,我吧代码贴上,大家帮帮小弟!
程序代码:
Public Structure LASTINPUTINFO   '定义数据类型
    Public cbSize                  '添加的两个成员

    Public dwTime
End Structure


===================================

Public Declare Function GetLastInputInfo Lib "user32 " (ByRef LASTINPUTINFO As LASTINPUTINFO) As Boolean

============================================

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim A As LASTINPUTINFO, 启动时间 As Integer, 上一次活动时间 As Integer, 已闲置时间 As Integer, 地址

        地址 = WebBrowser1.Url
        A.dwTime = 0
        A.cbSize = 8
        启动时间 = Environment.TickCount / 1000


        GetLastInputInfo(A)
      

        cs1.Text = 启动时间

        上一次活动时间 = A.dwTime / 1000

        cs2.Text = 上一次活动时间

        已闲置时间 = 启动时间 - 上一次活动时间

        cs3.Text = 已闲置时间




        If 已闲置时间 = 5 Then
            MsgBox("时间到了!")
        End If













    End Sub


上一次活动时间 的值一直获取不到,一直都是0




[ 本帖最后由 zxdw520 于 2011-3-19 20:51 编辑 ]
1 回复
#2
zxdw5202011-03-20 10:44
高手些呢,请大家帮帮忙,有其他办法也行的。
1