Solved

moving mouse so it cancel screen saver

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

724 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