OB1Canobie
asked on
Application to move mouse
I have a need to write an application in vb.net to move the mouse cursor every 4 minutes. The mouse movement can be minimal, but enough to keep screen saver from coming on. Does anyone have code to do this?
Windows.Forms.Cursor.Posit ion = New System.Drawing.Point(Windo ws.Forms.C ursor.Posi tion.X + 1, Windows.Forms.Cursor.Posit ion.Y + 1)
Disable the screen saver instead;
Imports Microsoft.Win32
'// This goes on form_load
'// Reads and sets the registry to disable screensaver from kicking
Dim regKey As RegistryKey
Dim regVal As String
regKey = Registry.CurrentUser.OpenSubKey("Control Panel\Desktop", True)
regVal = regKey.GetValue("ScreenSaveActive")
If regVal = 1 Then
regKey.SetValue("ScreenSaveActive", "0")
End If
regKey.Close()
'//This goes on app exit
'// Reads and sets the registry to re-enable screensaver
Dim regKey As RegistryKey
Dim regVal As String
regKey = Registry.CurrentUser.OpenSubKey("Control Panel\Desktop", True)
regVal = regKey.GetValue("ScreenSaveActive")
If regVal = 0 Then
regKey.SetValue("ScreenSaveActive", "1")
End If
regKey.Close()
OR Do like this:
Microsoft.Win32.RegistryKey rkScreenSaver = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@" Control Panel\Desktop", true );
if ( (string)rkScreenSaver.GetValue( "ScreenSaveActive" ) == "1" )
{
rkScreenSaver.SetValue( "ScreenSaveActive", "0" );
rkScreenSaver.Close( );
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In the example above which I never mentioned you would periodically call SetThreadExecutionState() once every minute is fine. When your finished and you want it to go back to normal use SetThreadExecutionState(ES _CONTINUOU S).
Thanks for posting that one egl1044. Learned something new today! =D
No problem Idle_Mind it's very useful for background processing. I would like to also point out is that I have always called this routine periodically but it's appears only neccessary if you use only ES_CONTINUOUS flag.
If you use both flags ES_CONTINUOUS | ES_DISPLAY_REQUIRED it locks the Idle counter all together until you remove the ES_DISPLAY_REQUIRED bit flag. That means with the two flags you only need call it once but periodically if using only ES_CONTINUOUS.
When I started using this the documentation wasn't the same from a couple years ago but they seem to have improved it over time with much better descriptions.
If you use both flags ES_CONTINUOUS | ES_DISPLAY_REQUIRED it locks the Idle counter all together until you remove the ES_DISPLAY_REQUIRED bit flag. That means with the two flags you only need call it once but periodically if using only ES_CONTINUOUS.
When I started using this the documentation wasn't the same from a couple years ago but they seem to have improved it over time with much better descriptions.
Whoops the above should read
If you use SetThreadExecutionState without* ES_CONTINUOUS flag.
That means with the two flags you only need call it once but periodically if using SetThreadExecutionState without* ES_CONTINUOUS flag.
<Fills up more coffee>...
If you use SetThreadExecutionState without* ES_CONTINUOUS flag.
That means with the two flags you only need call it once but periodically if using SetThreadExecutionState without* ES_CONTINUOUS flag.
<Fills up more coffee>...