Click to See Complete Forum and Search --> : How does Windows know when to call the screensaver?
Vynia
Dec 14th, 1999, 03:58 PM
Is there an API-call or something to check how much time passed since the last keypress
or mouse movement?
Juillet
Dec 14th, 1999, 05:51 PM
Timer Control
Vynia
Dec 15th, 1999, 06:24 PM
Well, this might work for one single application but not for the whole system. using just a timer control I couldn't access the events of all other apps running, could I? Subclassing Windows isn't possible, too (would be quite nice ;-))!
Create a new form and add a label and a timer called Label1 and Timer1.
Use the GetAsyncKeyState to see if a key was pressed since the last time we checked the key.
And the GetCursorPos to check the last cursor position.
Option Explicit
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Sub Form_Load()
'Init timer
Timer1.Interval = 100
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Dim bActive As Boolean
Dim iCounter As Integer 'Counter to walk throug all key's
Dim pCursPos As POINTAPI 'Cursor pos
Static plCursPos As POINTAPI 'Store last cursor posistion
Static datTime As Date
'Loop through every key
For iCounter = 1 To 256
If GetAsyncKeyState(iCounter) <> 0 Then
'Key was pressed since last time we checked
bActive = True
Exit For
End If
Next
'Get the cursor pos
GetCursorPos pCursPos
'Check the cursor pos with the last cursorpos
If pCursPos.x <> plCursPos.x Or pCursPos.y <> plCursPos.y Then
bActive = True
End If
'Store the cursor pos for next time
plCursPos = pCursPos
'There has been some activity reset the time
If bActive = True Then
datTime = Now
End If
Label1 = "Inactive for " & DateDiff("s", datTime, Now) & " sec."
End Sub
------------------
Vincent van den Braken
EMail: azzmodan@azzmodan.demon.nl
ICQ: 15440110 (http://www.icq.com/15440110)
Homepage: http://www.azzmodan.demon.nl
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.