模拟鼠标点击事件 mouse_move

using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace Mixi
{
    public partial class FrmTest : Mixi.FrmBase
    {
         [DllImport("user32.dll")]
        static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);


        [Flags]
        public enum MouseEventFlags
        {
            LEFTDOWN = 0x00000002,
            LEFTUP = 0x00000004,
            MIDDLEDOWN = 0x00000020,
            MIDDLEUP = 0x00000040,
            MOVE = 0x00000001,
            ABSOLUTE = 0x00008000,
            RIGHTDOWN = 0x00000008,
            RIGHTUP = 0x00000010
        }


        public static void LeftClick(int x, int y)
        {
            Cursor.Position = new System.Drawing.Point(x, y);
            mouse_event((int)(MouseEventFlags.LEFTDOWN), 0, 0, 0, 0);
            mouse_event((int)(MouseEventFlags.LEFTUP), 0, 0, 0, 0);
        }
        public FrmTest()
        {
            try
            {
                InitializeComponent();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }




        }
        private void button1_Click(object sender, EventArgs e)
        {
            //Call the imported function with the cursor's current position
            int X = Cursor.Position.X + 100;
            int Y = Cursor.Position.Y + 10;
            LeftClick(X, Y);
        }


        private void FrmTest_Load(object sender, EventArgs e)
        {


        }
        


        private void FrmTest_KeyPress(object sender, KeyPressEventArgs e)
        {
            int X = Cursor.Position.X ;
            int Y = Cursor.Position.Y ;
            for(int i =0;i<10;i++)
            {
                Console.WriteLine("click");
                textBox1.Text += i.ToString() + ";";
                LeftClick(X + 20 * i, Y);
            }
        }


        private void button2_Click(object sender, EventArgs e)
        {
            Console.WriteLine("click");
            MessageBox.Show("click me");
        }

    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值