[英]Distinguish clicks from mouse_event with hardware clicks
My goal is to make a program that auto-clicks when the user mouse button is pressed down.我的目标是制作一个在用户按下鼠标按钮时自动点击的程序。
At this moment, I have this.此刻,我有这个。
while (true)
{
Sleep(1);
if (GetAsyncKeyState(VK_LBUTTON))
{
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
Sleep(delayy);
But when I use this it just starts a loop, because the program will keep detecting the clicks and keep sending more inputs.但是当我使用它时它只是开始一个循环,因为程序会不断检测点击并不断发送更多的输入。 How can I resolve this?
我该如何解决这个问题?
To determine if a button or key is pressed down you can use this:要确定按钮或键是否被按下,您可以使用以下命令:
if((GetKeyState(VK_LBUTTON) & 0x100) != 0)
For the code you are looking, you can try the following:对于您正在查找的代码,您可以尝试以下操作:
#include <iostream>
#include <Windows.h>
int main()
{
while (1)
{
if (GetAsyncKeyState(VK_LBUTTON)) {
keybd_event(VK_LBUTTON, 0x45, KEYEVENTF_KEYUP, 0);
while (!GetAsyncKeyState(VK_LBUTTON))
{
keybd_event(VK_LBUTTON, 0x45, 0, 0);
std::cout << "Click" << std::endl;
}
}
Sleep(100);
}
}
This might need some optimization and fix but you can sort it out in your code.这可能需要一些优化和修复,但您可以在代码中进行整理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.