|
-
Dec 14th, 1999, 04:58 PM
#1
Thread Starter
New Member
Is there an API-call or something to check how much time passed since the last keypress
or mouse movement?
-
Dec 14th, 1999, 06:51 PM
#2
Member
-
Dec 15th, 1999, 07:24 PM
#3
Thread Starter
New Member
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 ;-))!
-
Dec 15th, 1999, 08:19 PM
#4
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.
Code:
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: [email protected]
ICQ: 15440110
Homepage: http://www.azzmodan.demon.nl
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
|