Solved

moving mouse so it cancel screen saver

Posted on 2009-05-18
1
740 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET 2008 - SQL Timeout 9 51
Asp.Net Session Question 2 36
VB.net VSTO Excel Ribbon error 4 14
reading an excel file vb.net 2 21
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
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…

730 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