click - 自动点击器或模拟点击<包含代码>
问题描述
我认为这可能对修改自动点击器的代码或在任何 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";
}
}
}
希望这段代码有帮助
解决方案
推荐阅读
- c# - 关闭 wpf 窗口时如何判断 await 是否正在运行或已完成运行
- jwt - JSON Web 令牌 (JWT) 是否适合服务器到服务器的身份验证?
- ios - ios(Xcode):根据设备屏幕大小调整启动屏幕图标的大小
- amazon-web-services - AWS 存储桶策略语句优先顺序
- flutter - 如何从flutterWebViewPlugin(webview)中获取HTML字段值
- android-studio - 着色字符串的子字符串
- linux - USB端口监控
- python - 有效计算元素的出现次数
- python - 带有多个子句的 Numpy 索引
- python - 如何修复 PyCharm python 控制台提示符?