首页 > 解决方案 > 自动点击器或模拟点击<包含代码>

问题描述

我认为这可能对修改自动点击器的代码或在任何 C# 应用程序中模拟鼠标点击很有帮助和容易。这是我的代码。我为计时器使用了 2 个按钮,一个用于开启,一个用于关闭,然后是一个文本框和一个按钮,只需在每次按下按钮时在文本框中添加一个 1 即可查看它是否有效。代码在光标当前位置的位置单击鼠标。希望这可以帮助。随意提出任何代码建议。

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

namespace AutoClicker
{
    public partial class Form1: Form
    {

        [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);
        //Mouse actions
        private const int MOUSEEVENTF_LEFTDOWN = 0x02;
        private const int MOUSEEVENTF_LEFTUP = 0x04;
        private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
        private const int MOUSEEVENTF_RIGHTUP = 0x10;

        public Form1()
        {
            InitializeComponent();

    }

        private void Form1_Load(object sender, EventArgs e)
        {
                  uint X = (uint)Cursor.Position.X;
                  uint Y = (uint)Cursor.Position.Y;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Enabled = true;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            timer1.Enabled = false;

        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            uint X = (uint)Cursor.Position.X;
            uint Y = (uint)Cursor.Position.Y;
            mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
        }
        private void button3_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1. Text + "1";
        }
    }
}

希望这段代码有帮助

标签: clickmouse

解决方案


推荐阅读