c# - 自动点击器 Visual Studio CS
问题描述
我试图制作自己的自动点击器。一切都很顺利。
但是当我按下按钮时,它只会将状态从关闭更改为开启..但没有任何反应。
我尝试了很长时间来检查错误,但我没有找到任何错误。这是我的脚本,如果您发现任何错误,请告诉我!
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
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.Threading;
namespace BetaClicker
{
public partial class form1 : Form
{
[DllImport(dllName:"user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
private const int LEFTUP = 0x0004;
private const int LEFTDOWN = 0x0002;
public form1()
{
InitializeComponent();
}
private void clicktimer_Tick(object sender, EventArgs e)
{
Random rnd = new Random();
int maxcps = (int)Math.Round(1000.0 / (trackBar1.Value + trackBar2.Value * 0.2));
int mincps = (int)Math.Round(1000.0 / (trackBar1.Value + trackBar2.Value * 0.4));
try
{
clicktimer.Interval = rnd.Next(mincps, maxcps);
}
catch
{
//Ignored
}
bool mousdown = MouseButtons == MouseButtons.Left;
if (mousdown)
{
mouse_event(dwFlags:LEFTDOWN, dx:0,dy:0,cButtons:0,dwExtraInfo:0);
Thread.Sleep(millisecondsTimeout: rnd.Next(1, 6));
mouse_event(dwFlags: LEFTUP, dx: 0, dy: 0, cButtons: 0, dwExtraInfo: 0);
}
}
private void button1_Click(object sender, EventArgs e)
{
if (button1.Text.Contains("on"))
{
clicktimer.Start();
button1.Text = "Toggle: off";
}
else
{
clicktimer.Stop();
button1.Text = "Toggle: on";
}
}
}
}
解决方案
我可以建议您使用以下内容更改您单击的代码部分:
int X = Cursor.Position.X;
int Y = Cursor.Position.Y;
mouse_event(LEFTDOWN | LEFTUP, X, Y, 0, 0);
我认为您的问题是您开始单击但始终位于坐标 (0, 0) 处的屏幕位置,因此没有任何反应。
此外,您实际上并不需要 LEFTDOWN 动作和 LEFTUP 动作的超时
如果您不想单击刚刚设置光标的位置X
并Y
使用所需的值(坐标)
推荐阅读
- jquery - jQuery 嵌套选择器不工作,但 find() 工作正常
- c# - -已解决- Socket Exception - 无法建立连接,因为目标机器主动拒绝它
- python - 用实例填充二维数组
- java - java zoneddatetime:计算时保留时区ID
- python - 根据组的天间隔为列分配值的优雅方法
- ssis-2012 - 目标实体未出现在 CRM SSIS 目标编辑器中
- pentaho - 如何从 Pentaho 的图表中显示带有动态参数的报告?
- reactjs - 在 React js 中为 Select 标签的 value 属性赋值
- c# - c#:理解和消费XMLDiff差异-文件
- matlab - 长时间录制时如何停止跳过数据?