Solved

moving mouse so it cancel screen saver

Posted on 2009-05-18
1
725 Views
Last Modified: 2012-05-07
i have the code below with the intention of moving the mouse so the screen saver gets canceled. however it doesn't work. My mouse move but the screen saver still start. is there anything i need to do to make it stop? please help.
Imports System.Windows.Forms
Public Class MouseMover
    Inherits System.Windows.Forms.Form
    <Runtime.InteropServices.DllImport("user32.dll", SetLastError:=True)> _
    Private Shared Function SetCursorPos(ByVal X As Integer, ByVal Y As Integer) As Boolean
    End Function
 
    Private Sub MouseMover_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Start()
        Timer1.Enabled = True
        Timer1.Interval = 30000
        Me.Visible = False
        Me.ShowInTaskbar = False
        Me.NotifyIcon1.Icon = Me.Icon
        Me.NotifyIcon1.Visible = True
    End Sub
 
    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim random As New Random
        Dim x As Integer = random.Next
        Dim y As Integer = random.Next
        SetCursorPos(x, y)        
    End Sub
 
    Private Sub NotifyIcon1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles NotifyIcon1.DoubleClick
        NotifyIcon1.Dispose()
        Application.Exit()
 
    End Sub
End Class

Open in new window

0
Comment
Question by:StewSupport
1 Comment
 
LVL 1

Accepted Solution

by:
ckontz earned 500 total points
ID: 24418412
Windows knows the difference between the cursor moving through code instead of the actual mouse moving.  The solution is to use the ScreenSaver API calls to cancel the screensaver.

Fortunately, someone has already written a nice class in C# that encapsulates these API calls:
http://www.codeproject.com/KB/cs/ScreenSaverControl.aspx.  You would need to create a C# project or put the class in a Class Library and reference it from your project.

Fortunately, someone has already created what it looks like you're trying to do:  Caffeine.  For more info, go to: http://www.softpedia.com/get/Others/Miscellaneous/Caffeine.shtml

Add this class to your project then change your code as follows:
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question