惊雷无声 发表于 2023-1-9 13:58:39

winform实现模拟鼠标点击

移动鼠标到你想要的位置,然后进行点击,某些时候是很有用的
https://img2023.cnblogs.com/blog/1423021/202301/1423021-20230109112110708-427359849.png
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;

      
      public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo); //*-填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息--填充信息-*//

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
页: [1]
查看完整版本: winform实现模拟鼠标点击