Solved

moving mouse so it cancel screen saver

Posted on 2009-05-18
1
713 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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now