-
I'm writing program that will automatically 'do something' if the pc has been idle for a certain about of time, sort of like and screen saver.. But this is where I get stuck, how can I make my program know when a key is pressed or the mouse has been moved, so that the idle timer can be restarted.
note: The program will be hidden since its going to be like an screen saver.
-
Put a Function to reset the Timer in the Form's MouseMove and KeyPress events.
-
Since the PC is in Idle mode, The MouseMove and KeyPress events may not work although we really move it. It must something deal with the API function call.
-
But in order to use the form MouseMove and KeyPress, you'll have to do that on the from.. That won't be possible since the form is hidden. I know it has something to do with subclassing and api calls, but which ones?
-
Screen Saver?
Hi
Are you creating Screen Saver? If so, there is a special way to do it. Just put the string SCRNSAVE: prefix to the Application title dialog box in VB. Compile as .scr file. Windows will run your application.
The matter of terminating the screen saver is easy. Ignore the first MouseMove event and KeyDown Event.
Hope it works!
-
I'm not trying to make a screen saver, just an app that would 'do something' of the pc has been idle for a certain amount of time.. But I'm tying to reset the idle time on the program of a key is pressed or if the mouse is moved at anytime, even if my program isn't visable [the from is hidden, so I know I can't use KeyPress or MouseMove]
-
Use API
I suggest you to use mouse_event and keybd_event API Calls. These are called when the user moves mouse or press a key. They also let you Move the mouse.
-
GetKeyState API
Hi nopd-officer, Finally I manage to get you a solution but may not be a good solution. Whereby, you need to use a Timer (set the interval to 250ms. If you nedd a faster respond) and GetKeyState API function as below:
But, this code have a defact, where the user need to hold the Esc key at least 500ms.
Code:
Option Explicit
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Private Const VK_ESCAPE = &H1B
Private Sub Form_Load()
Me.Hide
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
If GetKeyState(VK_ESCAPE) < 0 Then
Me.Show
Timer1.Enabled = False
End If
-
Thanks.. I messed around with some things and got it to work