移动鼠标并单击 [英] move mouse and click
本文介绍了移动鼠标并单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想写一个自动键盘和鼠标程序首先我从设置鼠标位置开始并点击
i设置鼠标位置不在形式但是我如何点击?
i want write a auto keyboard and mouse program first i start with set mouse position and click
i set mouse position out of form but how can i click ?
private void button1_Click(object sender, EventArgs e)
{
Cursor.Position = new Point( 500, 500);
}
推荐答案
如果您只想在Windows窗体中执行此操作,可以试试这个:
If you are only looking to do this with in the windows form you could try this:
this.OnMouseClick(new MouseEventArgs(MouseButtons.Left,1,500,500,0));
你可以在这里点击鼠标:
you will be able to pick up the mouse click in here:
private void Form1_MouseClick(object sender, MouseEventArgs e)
{
Label lbl = new Label();
lbl.Top = e.Y;
lbl.Left = e.X;
lbl.Height = 25;
lbl.Width = 100;
lbl.Text = "You clicked here!.";
this.Controls.Add(lbl);
}
我不确定你真的需要去那里。
看起来你需要模拟鼠标点击。这是由原始Windows APISendInput
完成的: http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx [ ^ ]。
这是通过P / Invoke在.NET中的方法:http://www.pinvoke.net/default.aspx/user32.sendinput [ ^ ]。
请注意,鼠标模拟不应用于UI开发。它只能用于特殊用途,例如键盘和鼠标宏。
-SA
I''m not sure you really need to go there.
It looks like you need to simulate mouse click. This is done by raw Windows APISendInput
: http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx[^].
This is how to do in .NET, via P/Invoke: http://www.pinvoke.net/default.aspx/user32.sendinput[^].
Please understand that mouse simulation should not be used for UI development. It can only be used for special purposes, such as keyboard and mouse macro.
—SA
这篇关于移动鼠标并单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文