?
Solved

moving mouse so it cancel screen saver

Posted on 2009-05-18
1
Medium Priority
?
760 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 1

Accepted Solution

by:
ckontz earned 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month10 days, 16 hours left to enroll

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