vb里怎么获取系统静止不动的时间?
就是获取没有按过键盘,动过鼠标的累计时间?
如果一旦动过,则重新计时。
[解决办法]
To a form, add a label (Label1) and a command button (Command1) along with the following code:
--------------------------------------------
Option Explicit
' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
' Copyright ©1996-2006 VBnet, Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
' Distribution: You can freely use this code in your own
' applications, but you may not reproduce
' or publish this code on any web site,
' online service, or distribute as source
' on any media without express permission.
' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
Private Type LASTINPUTINFO
cbSize As Long
dwTime As Long
End Type
Private Declare Function GetTickCount Lib "kernel32 " () As Long
Private Declare Function GetLastInputInfo Lib "user32 " (plii As Any) As Long
Private Sub Form_Load()
Command1.Caption = "Stop "
Timer1.Interval = 10 'ms
Timer1.Enabled = True
Label1.Caption = "system idle (secs): "
End Sub
Private Sub Command1_Click()
Timer1.Enabled = Not Timer1.Enabled
Select Case Timer1.Enabled
Case True
Command1.Caption = "Stop "
Case False
Command1.Caption = "Start "
End Select
End Sub
Private Sub Form_Unload(Cancel As Integer)
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
Dim lii As LASTINPUTINFO
lii.cbSize = Len(lii)
Call GetLastInputInfo(lii)
With Label1
.Caption = "system idle (secs): " & FormatNumber((GetTickCount() - lii.dwTime) / 1000, 2)
.Refresh
End With
End Sub