|
-
Mar 28th, 2000, 03:46 AM
#1
Thread Starter
New Member
Does anyone know of a Win API function that returns the length of time that a workstation has been idle (no keyboard or mouse activity). I need to be able to time-out an application after a specified interval. I'm sure Windows must provide this function because I imagine utilities like screensavers and Instant Messenger use it. But I don't seem to be able to find such a function in the Win API references I've used. I currently use VB5 on Windows NT. Thanks for your help.
Lew.
-
Mar 28th, 2000, 05:44 AM
#2
Frenzied Member
You can use the GetCursorPos API to get the cursor position. Save the cursor position value into a private variable once in form load, and then in a timer and get the new value into a temporary variable. If they match, then you can increment your private timer variable (assuming the user hasn't pressed a key). If they don't match, then the user moved the mouse, so the private cursor position variable should be updated to the new temp variable, and the private timer variable should be reset to 0.
Use the GetAsyncKeyState and GetKeyboardState APIs to capture keypresses. If the user hasn't pressed a key, then increment the timer. If they have, then reset the timer to 0.
Combine these two processes so you have something like this pseudocode:
Code:
'This would be inside a Timer Event
If Not MouseMoved() And Not KeyPressed() Then
IncrementTimerVariable()
Else
SetTimerToZero()
End If
Then, you can have another function that tests the value of your Timer variable, and if it is greater than or equal to a set value, you disable your application, as in this pseudocode:
Code:
'This is also in the Timer Event
If TimerVariable >= MaxAllowedIdleTime Then
DisableApp()
End If
-
May 8th, 2000, 12:24 AM
#3
New Member
User Idle Time
You can use the GetCursorPos and GetKeyboardState and it works fine in a DLL that is used by a standard VB form with a timer. However, if you reference the DLL in a web page using SetInterval as the timer, it only works if you set the timer to about 100 milliseconds or prolong the keyboard or mouse event for the duration of the timer interval. What could possibly be wrong?
[email protected]
-
Jul 6th, 2000, 05:25 PM
#4
New Member
Detecting idle time
What I am trying to figure out right now is how to use
getProcessTimes
and figure out if over the last minute if the systemIdleProcess has had one minute's time. If I could figure out how to use the bloody thing, it would help.
davis
One man's variable is another man's constant
-
Nov 18th, 2000, 09:29 AM
#5
Hyperactive Member
"One logical slip and an entire scientific edifice comes tumbling down." - Robert M. Pirsig
[email protected]
"but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.
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
|