自动点击程序或模拟点击

问题描述 投票:0回答:1

我认为这可能对修改自动点击程序的代码或在任何C#应用程序中模拟鼠标单击都是有用且容易的,这是我的代码。我为定时器使用2个按钮,一个为ON,一个为OFF,然后是一个文本框和一个按钮,通过在每次按下按钮时在文本框中添加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";
        }
    }
}

希望此代码有帮助

click mouse
1个回答
0
投票

如果不起作用,这将成为lua cuz的代码

© www.soinside.com 2019 - 2024. All rights reserved.