|
-
Feb 1st, 2000, 03:16 AM
#1
Thread Starter
New Member
Does anyone know a way to tell how long your computer has been idle? Windows 2000 has an API for this, but 9*/NT do not as far as I know. Thanks in advance!
Ryan
[email protected]
-
Feb 1st, 2000, 03:59 AM
#2
Add a Timer to a Form:
Code:
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Sub Form_Load()
Timer1.Interval = 100
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Static tTimer As Single
Static tLastPos As POINTAPI
Dim tCurPos As POINTAPI
Dim iKey As Integer
Timer1.Enabled = False
If tLastPos.x = 0 And tLastPos.y = 0 Then
'First Time, Setup the Variables
tTimer = Timer
Call GetCursorPos(tLastPos)
End If
'Check for Activity
Call GetCursorPos(tCurPos)
If tCurPos.x <> tLastPos.x Or tCurPos.y <> tLastPos.y Then
'Mouse Movement
tTimer = Timer
Else
For iKey = 1 To 255
If GetAsyncKeyState(iKey) Then Exit For
Next
If iKey > 255 Then
'No Activity, Idling
Caption = "Idle Time: " & Int(Timer - tTimer) & " Seconds."
Else
'Key/Mouse Button Pressed
tTimer = Timer
End If
End If
tLastPos.x = tCurPos.x
tLastPos.y = tCurPos.y
Timer1.Enabled = True
End Sub
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
-
Jul 12th, 2001, 11:31 AM
#3
Fanatic Member
I was searching for code to give the system idle time, and a lot of the posts I found were never resolved, so for future reference, this code works great, after replacing "<>" with "<>" and ">" with ">".
Just an FYI.
Here it is, edited:
VB Code:
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Sub Form_Load()
Timer1.Interval = 100
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Static tTimer As Single
Static tLastPos As POINTAPI
Dim tCurPos As POINTAPI
Dim iKey As Integer
Timer1.Enabled = False
If tLastPos.x = 0 And tLastPos.y = 0 Then
'First Time, Setup the Variables
tTimer = Timer
Call GetCursorPos(tLastPos)
End If
'Check for Activity
Call GetCursorPos(tCurPos)
If tCurPos.x <> tLastPos.x Or tCurPos.y <> tLastPos.y Then
'Mouse Movement
tTimer = Timer
Else
For iKey = 1 To 255
If GetAsyncKeyState(iKey) Then Exit For
Next
If iKey > 255 Then
'No Activity, Idling
Caption = "Idle Time: " & Int(Timer - tTimer) & " Seconds."
Else
'Key/Mouse Button Pressed
tTimer = Timer
End If
End If
tLastPos.x = tCurPos.x
tLastPos.y = tCurPos.y
Timer1.Enabled = True
End Sub
Last edited by VictorB212; Jul 12th, 2001 at 11:35 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|