C#鼠标点击器

本文介绍了一款使用C#编写的简易应用程序,该程序能够模拟鼠标的左键点击行为,并通过定时器控制点击频率。用户可以设置点击间隔,程序会验证输入是否为整数,并在符合条件时启动自动点击。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Runtime.InteropServices;

using System.Threading;

using System.Text.RegularExpressions;

 

namespace WindowsFormsApplication5

{

    public partial class Form1 : Form

    {

        [DllImport("user32")]

        private static extern int mouse_event(int dwFlags,int dx,int dy,int cButtons,int dwExtraInfo);

        const int MOUSEEVENT_LEFTDOWN = 0x0002;

        const int MOUSEEVENT_LEFTUP = 0x0004;        

        public Form1()

        {

            InitializeComponent();

        }

 

        private void button1_Click(object sender, EventArgs e)

        {

            string pattern=@"^/d+(/./d)?$";

            timer1.Enabled = true;

            if (Regex.IsMatch(textBox2.Text, pattern))

            {

                timer1.Interval = int.Parse(this.textBox2.Text);

                timer1.Start();

            }

            else

            {

                timer1.Stop();

                timer1.Enabled = false;

                MessageBox.Show("请输入整数!","系统提示:",MessageBoxButtons.OK,MessageBoxIcon.Error);                

            }                       

 

        }

 

        private void Mouse_Click()

        {                                               

            mouse_event(MOUSEEVENT_LEFTDOWN, 0, 0, 0, 0);

            mouse_event(MOUSEEVENT_LEFTUP, 0, 0, 0, 0);

            textBox2.Focus();

        }       

 

        private void timer1_Tick(object sender, EventArgs e)

        {            

            Mouse_Click();

        }

 

        private void Form1_Load(object sender, EventArgs e)

        {

            textBox2.Focus();

        }

 

        private void textBox2_Click(object sender, EventArgs e)

        {

            this.textBox2.SelectAll();

        }

 

        private void textBox2_KeyDown(object sender, KeyEventArgs e)

        {

            string pattern = @"^/d+(/./d)?$";

            if (e.KeyCode == Keys.PageUp)

            {

                if (Regex.IsMatch(textBox2.Text, pattern))

                {

                    timer1.Enabled = true;

                    timer1.Interval = int.Parse(this.textBox2.Text);

                    timer1.Start();

                }

                else

                {

                    timer1.Stop();

                    timer1.Enabled = false;

                    MessageBox.Show("错误:请输入整数!", "系统提示:", MessageBoxButtons.OK, MessageBoxIcon.Error);

                }

            }

            else if (e.KeyCode == Keys.PageDown)

            {

                timer1.Enabled = true;

                timer1.Stop();

            }

        }

    }

}

 

C#同样能实现鼠标点击功能,我试着写了一个,玩游戏的朋友们应该用的着,希望对你们有用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值