[英]How can I delay a function without freezing the thread using C++
I'm trying to delay a Right Button click using C++,我正在尝试使用 C++ 延迟右键单击,
Right now I have现在我有
if (GetKeyState(VK_LBUTTON) > 0) {
delay(120);
}
It works fine but while it's executing the program freezes.它工作正常,但在执行程序时冻结。 Is there a way I can make it delay the click but without freezing the Program?.
有没有办法让它延迟点击但不冻结程序?。
If you want to delay when an action occurs, then you should set a timer for it.如果你想在一个动作发生时延迟,那么你应该为它设置一个计时器。 Your program shouldn't just
delay
because it still needs to handle mouse events and graphics during that time.您的程序不应该只是
delay
因为在此期间它仍然需要处理鼠标事件和图形。 By setting a timer, the action will occur at the appropriate time without the rest of the program freezing.通过设置计时器,动作将在适当的时间发生,而不会冻结程序的其余部分。
Here's the microsoft guide on using timers: https://docs.microsoft.com/en-us/windows/desktop/winmsg/using-timers这是使用计时器的微软指南: https : //docs.microsoft.com/en-us/windows/desktop/winmsg/using-timers
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.