Tuesday, 13 August 2013

Easiest way to simulate user action to prevent system being considered idle

Easiest way to simulate user action to prevent system being considered idle

I know this question must have been asked hundreds of times before and so,
maybe, I'm just doing something wrong. But I have a WinForms program I'm
writing to try and keep the system appearing active so as to stop it as
registering idle.
I figured that having a Timer on my form and doing something as simple as
either moving the mouse via System.Windows.Forms.Cursor.Position or using
the SendKeys.Send method would be enough to register user interaction, but
it's not registering as user action and still letting the system appear as
inactive after a set amount of time.
My code is fairly straightforward... Either:
Private Sub Updater_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Updater.Tick
SendKeys.Send("+")
End Sub
Or doing something along the lines of:
Private Sub Updater_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Updater.Tick
Dim MyMousePosition As Point
MyMousePosition = Windows.Forms.Cursor.Position
Windows.Forms.Cursor.Position = New Point(MyMousePosition.X - 10,
MyMousePosition.Y)
End Sub
But neither is doing the trick... How can I get this to work AND
preferably in a way that would be of least inconvnience to a user if they
are actually using the system? (Meaning that I don't want to send a bunch
of keys that may mess up the user if they're actually being active or move
the mouse clear across the screen)
I know this coce is in VB, but I'm good with VB / C# solutions.
Thanks!!!

No comments:

Post a Comment