求一个C#鼠标轨迹记录程序代码
这个程序按下F1就会开始录制鼠标操作轨迹,然后按F2停止,按F3就开始按照录制了的鼠标轨迹进行自动操作,一直循环到按下F4为止!有没有高人能做个这个程序,提供个代码?实在...
这个程序按下F1就会开始录制鼠标操作轨迹,然后按F2停止,按F3就开始按照录制了的鼠标轨迹进行自动操作,一直循环到按下F4为止!有没有高人能做个这个程序,提供个代码?实在没有分了,20分求个代码!望有大侠帮帮忙,谢谢了!
展开
2个回答
展开全部
.cs文件
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace MyWindows
{
public partial class Form3 : Form
{
private IList<Point> list = new List<Point>();
public Form3()
{
InitializeComponent();
}
private void Form3_KeyUp(object sender, KeyEventArgs e)
{
switch (e.KeyData)
{
case Keys.F1:
list.Clear();
lblMsg.Text = "开始录制鼠标轨迹";
this.MouseMove += new MouseEventHandler(Form3_MouseMove);
break;
case Keys.F2:
if (list.Count == 0)
{
lblMsg.Text = "还没有录制";
return;
}
lblMsg.Text = "停止鼠标轨迹";
this.MouseMove -= new MouseEventHandler(Form3_MouseMove);
break;
case Keys.F3:
if (list.Count == 0)
{
lblMsg.Text = "还没有录制";
return;
}
lblMsg.Text = "开始播放鼠标轨迹";
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Start();
break;
case Keys.F4:
if (list.Count == 0)
{
lblMsg.Text = "还没有录制";
return;
}
lblMsg.Text = "停止播放鼠标轨迹";
timer1.Stop();
timer1.Tick -= new EventHandler(timer1_Tick);
break;
}
}
void Form3_MouseMove(object sender, MouseEventArgs e)
{
Point p = new Point(e.X, e.Y);
list.Add(p);
}
int i = 0;
void timer1_Tick(object sender, EventArgs e)
{
if (i + 1 == list.Count) i = 0;
Cursor.Position = list[i];
i++;
}
}
}
.designer.cs文件
namespace MyWindows
{
partial class Form3
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.label1 = new System.Windows.Forms.Label();
this.lblMsg = new System.Windows.Forms.Label();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(305, 12);
this.label1.TabIndex = 0;
this.label1.Text = "F1:开始录制 F2:结束录制 F3:播放录制 F4:体制录制";
//
// lblMsg
//
this.lblMsg.AutoSize = true;
this.lblMsg.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
this.lblMsg.Location = new System.Drawing.Point(333, 9);
this.lblMsg.Name = "lblMsg";
this.lblMsg.Size = new System.Drawing.Size(0, 12);
this.lblMsg.TabIndex = 1;
//
// Form3
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(575, 477);
this.Controls.Add(this.lblMsg);
this.Controls.Add(this.label1);
this.Name = "Form3";
this.Text = "Form3";
this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.Form3_KeyUp);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label lblMsg;
private System.Windows.Forms.Timer timer1;
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace MyWindows
{
public partial class Form3 : Form
{
private IList<Point> list = new List<Point>();
public Form3()
{
InitializeComponent();
}
private void Form3_KeyUp(object sender, KeyEventArgs e)
{
switch (e.KeyData)
{
case Keys.F1:
list.Clear();
lblMsg.Text = "开始录制鼠标轨迹";
this.MouseMove += new MouseEventHandler(Form3_MouseMove);
break;
case Keys.F2:
if (list.Count == 0)
{
lblMsg.Text = "还没有录制";
return;
}
lblMsg.Text = "停止鼠标轨迹";
this.MouseMove -= new MouseEventHandler(Form3_MouseMove);
break;
case Keys.F3:
if (list.Count == 0)
{
lblMsg.Text = "还没有录制";
return;
}
lblMsg.Text = "开始播放鼠标轨迹";
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Start();
break;
case Keys.F4:
if (list.Count == 0)
{
lblMsg.Text = "还没有录制";
return;
}
lblMsg.Text = "停止播放鼠标轨迹";
timer1.Stop();
timer1.Tick -= new EventHandler(timer1_Tick);
break;
}
}
void Form3_MouseMove(object sender, MouseEventArgs e)
{
Point p = new Point(e.X, e.Y);
list.Add(p);
}
int i = 0;
void timer1_Tick(object sender, EventArgs e)
{
if (i + 1 == list.Count) i = 0;
Cursor.Position = list[i];
i++;
}
}
}
.designer.cs文件
namespace MyWindows
{
partial class Form3
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.label1 = new System.Windows.Forms.Label();
this.lblMsg = new System.Windows.Forms.Label();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(305, 12);
this.label1.TabIndex = 0;
this.label1.Text = "F1:开始录制 F2:结束录制 F3:播放录制 F4:体制录制";
//
// lblMsg
//
this.lblMsg.AutoSize = true;
this.lblMsg.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
this.lblMsg.Location = new System.Drawing.Point(333, 9);
this.lblMsg.Name = "lblMsg";
this.lblMsg.Size = new System.Drawing.Size(0, 12);
this.lblMsg.TabIndex = 1;
//
// Form3
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(575, 477);
this.Controls.Add(this.lblMsg);
this.Controls.Add(this.label1);
this.Name = "Form3";
this.Text = "Form3";
this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.Form3_KeyUp);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label lblMsg;
private System.Windows.Forms.Timer timer1;
}
}
更多追问追答
追问
请问能讲下需要在窗口添加什么控件、按钮等吗?谢谢!
追答
5个label和一个timer
展开全部
这个可以,在事件中 .用这个MouseMove这个鼠标移动事件,把鼠标移到控件就发生。!
代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_MouseMove(object sender, MouseEventArgs e)
{
MessageBox.Show("呵呵, 你碰到我了.!!!");
}
}
}
//呵呵 简单吧? ,自己去试试吧..!
代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_MouseMove(object sender, MouseEventArgs e)
{
MessageBox.Show("呵呵, 你碰到我了.!!!");
}
}
}
//呵呵 简单吧? ,自己去试试吧..!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询