I am looking for code to return the ammount of time the computer has been idle, I am working on a security program for someone and I want to make it re-activate after a certain ammount of idle time. (kind of like a screen saver)
thx
Printable View
I am looking for code to return the ammount of time the computer has been idle, I am working on a security program for someone and I want to make it re-activate after a certain ammount of idle time. (kind of like a screen saver)
thx
Use a Do...Loop statement:
Something along those lines should suit you well. You should put the first two declarations in a module and the second two declarations and the Do...Loop statement in Sub Main. Then you should be sure to show a hidden form (hence the form_keydown) before doing the loop and setting it's keypreview to TRUE. Then put the CheckInputs in the module and set the startup object to sub main. After the loop, make sure to put whatever code you want to execute after the loop.Code:Option Explicit
Dim KeyPressed as Boolean
Dim Rec as PointAPI
...
...
...
Dim A, B, C, D
Dim MS as Long
MS = 300000 '(set for 5 minutes)
A = GetTickCount 'reminder to declare this API
Do
D = CheckInputs
If D <> 0 Then A = D
DoEvents
B = GetTickCount
Loop Until C => MS
Function CheckInputs as Long
Dim Nw as PointAPI
If KeyPressed Then KeyPressed = False
GetCursorPos Nw 'reminder to declare this API
If Rec.X <> Nw.X or Rec.Y <> Nw.Y Then
CheckInputs = GetTickCount
Rec.X = Nw.X: Rec.Y = Nw.Y
End If
End Function
Private Sub Form_KeyDown(.... blah ...)
KeyPressed = True
End Sub
This may sound a little odd, but why don't you just make it EXACTLY like a screen saver? All screen savers are are .exe files with the extension changed to .scr. Just make a change to it to not run when the preview window passes it a /p parameter in the command$ string.
I had though of that, except I had one form running in the task bar to allow the user to change preferences etc. and when it is time the sercurity form loads. I have never used screen savers that way, although I have done some reading about it. I am trying to keep this as simple as I can because this is just a side project for a friend. I'm going to try the first bit of code and see if it does the trick.
Thx