winform嵌入虚拟键盘控件(winform实现模拟鼠标点击)
移动鼠标到你想要的位置,然后进行点击,某些时候是很有用的
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
private void button1_Click(object sender, EventArgs e)
{
var x = int.Parse(textBox1.Text);
var y = int.Parse(textBox2.Text);
Cursor.Position = new Point(x, y);
}
private void button2_Click(object sender, EventArgs e)
{
var x = int.Parse(textBox1.Text);
var y = int.Parse(textBox2.Text);
Cursor.Position = new Point(x, y);
System.Threading.Thread.Sleep(100);
// 模拟鼠标左键按下
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
// 模拟鼠标左键弹起
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
int MOUSEEVENTF_LEFTDOWN = 0x0002;
int MOUSEEVENTF_LEFTUP = 0x0004;
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com