using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SmartMouse
{
    class MouseSet
    {
        // 导入mouse_event函数
        [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);

        // 鼠标事件常量
        private const uint MOUSEEVENTF_LEFTDOWN = 0x02;
        private const uint MOUSEEVENTF_LEFTUP = 0x04;
        private const uint MOUSEEVENTF_RIGHTDOWN = 0x08;
        private const uint MOUSEEVENTF_RIGHTUP = 0x10;


        public  static  void SimulateLeftClick(int x, int y)
        {
            // 移动鼠标到指定位置
            Cursor.Position = new Point(x, y);
            // 模拟鼠标左键按下和释放
            mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, (uint)x, (uint)y, 0, 0);
        }

        public static  void SimulateRightClick(int x, int y)
        {
            // 移动鼠标到指定位置
            Cursor.Position = new Point(x, y);
            // 模拟鼠标右键按下和释放
            mouse_event(MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP, (uint)x, (uint)y, 0, 0);
        }
         // 移动鼠标到指定位置
        [DllImport("user32.dll")]
       public  static extern bool SetCursorPos(int x, int y);
         
    }
}

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐