C#如何自己触发mouseclick
用C#打算做一个鼠标每一秒自动移动到指定位置并点击一下的WindowsApplication.已经实现间隔一秒的光标移动请高人指点在每移动到指定位置的同时怎么使光标自己点...
用C#打算做一个 鼠标每一秒自动移动到指定位置并点击一下的WindowsApplication.
已经实现间隔一秒的光标移动
请高人指点在每移动到指定位置的同时怎么使光标自己点击一下 小弟万分感谢
public partial class Form1 : Form
{
Point mp;
public Form1()
{
InitializeComponent();
mp = new Point(0, 0);
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = !timer1.Enabled;
}
private void timer1_Tick(object sender, EventArgs e)
{
mp.X += 100;
if (mp.X > 1024)
{
mp.X = 0;
mp.Y += 100;
if (mp.Y > 768)
{
mp = new Point(0, 0);
}
}
Cursor.Position = mp;
} 展开
已经实现间隔一秒的光标移动
请高人指点在每移动到指定位置的同时怎么使光标自己点击一下 小弟万分感谢
public partial class Form1 : Form
{
Point mp;
public Form1()
{
InitializeComponent();
mp = new Point(0, 0);
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = !timer1.Enabled;
}
private void timer1_Tick(object sender, EventArgs e)
{
mp.X += 100;
if (mp.X > 1024)
{
mp.X = 0;
mp.Y += 100;
if (mp.Y > 768)
{
mp = new Point(0, 0);
}
}
Cursor.Position = mp;
} 展开
2个回答
展开全部
using System.Runtime.InteropServices;
#region API
[DllImport("user32.dll")]
static extern void mouse_event(MouseEventFlag flags, int dx, int dy, uint data, UIntPtr extraInfo);
[Flags]
enum MouseEventFlag : uint
{
Move = 0x0001,
LeftDown = 0x0002,
LeftUp = 0x0004,
RightDown = 0x0008,
RightUp = 0x0010,
MiddleDown = 0x0020,
MiddleUp = 0x0040,
XDown = 0x0080,
XUp = 0x0100,
Wheel = 0x0800,
VirtualDesk = 0x4000,
Absolute = 0x8000
}
#endregion
//以上代码放在Class 任意处
mouse_event(MouseEventFlag.LeftDown, 0, 0, 0, UIntPtr.Zero);
//执行左键按下
mouse_event(MouseEventFlag.LeftUp, 0, 0, 0, UIntPtr.Zero);
//执行左键松开
//完成一个单击动作
//之后执行以上代码便可模似鼠标单击一次
#region API
[DllImport("user32.dll")]
static extern void mouse_event(MouseEventFlag flags, int dx, int dy, uint data, UIntPtr extraInfo);
[Flags]
enum MouseEventFlag : uint
{
Move = 0x0001,
LeftDown = 0x0002,
LeftUp = 0x0004,
RightDown = 0x0008,
RightUp = 0x0010,
MiddleDown = 0x0020,
MiddleUp = 0x0040,
XDown = 0x0080,
XUp = 0x0100,
Wheel = 0x0800,
VirtualDesk = 0x4000,
Absolute = 0x8000
}
#endregion
//以上代码放在Class 任意处
mouse_event(MouseEventFlag.LeftDown, 0, 0, 0, UIntPtr.Zero);
//执行左键按下
mouse_event(MouseEventFlag.LeftUp, 0, 0, 0, UIntPtr.Zero);
//执行左键松开
//完成一个单击动作
//之后执行以上代码便可模似鼠标单击一次
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询