Tom Knowlton
asked on
Windows Application moves the mouse programmatically
I need a C# source code for a Windows Program that, when run...will programmatically move the mouse from Point A to Point B, then from Point B to Point A -- about once a minute.
I have this stupid monitor on my computer that locks my computer if I don't move the mouse periodically. I cannot disable the monitor....so I want to write this program to fool the OS into thinking I am doing something.
I have this stupid monitor on my computer that locks my computer if I don't move the mouse periodically. I cannot disable the monitor....so I want to write this program to fool the OS into thinking I am doing something.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
wow, your way looks a bit more complicated...
ASKER
Thank you, Yurich!
any time ;)
ASKER
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServ
namespace WindowsApplicationMoveMous
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
[DllImport("user32.dll")]
private static extern void mouse_event(
UInt32 dwFlags, // motion and click options
UInt32 dx, // horizontal position or change
UInt32 dy, // vertical position or change
UInt32 dwData, // wheel movement
IntPtr dwExtraInfo // application-defined information
);
private System.Windows.Forms.Timer
private System.ComponentModel.ICon
private bool changed;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
changed = false;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Cont
this.timer1 = new System.Windows.Forms.Timer
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Interval = 3000;
this.timer1.Tick += new System.EventHandler(this.t
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Name = "Form1";
this.Text = "Form1";
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void timer1_Tick(object sender, System.EventArgs e)
{
if(changed == false)
{
SendClick(new System.Drawing.Point(50,50
}
else
{
SendClick(new System.Drawing.Point(100,1
}
changed = !changed;
}
public static void SendClick(Point location)
{
Cursor.Position = location;
mouse_event(1, 0, 0, 0, new System.IntPtr());
mouse_event(1, 0, 0, 0, new System.IntPtr());
}
}
}
Is there a better....or easier way?????