简体   繁体   English

如何使用 C++ 在不冻结线程的情况下延迟函数

[英]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.

相关问题 使用创建延迟()函数<thread> (C++) - Creating a delay() function using <thread> (C++) 如何在不使用C ++ 11线程的情况下使用functor作为线程函数在Windows中开始线程? - How can I begin thread in windows using functor as thread function without using C++11 thread? C ++线程休眠而不冻结当前线程 - c++ thread sleep without freezing current thread 在没有使用睡眠的延迟之后在C ++中执行函数 - execute function in C++ after a delay without using sleep 如何在不使用C ++ / C的阻塞函数的情况下将值从线程返回到主函数 - How to return value from the thread back to main function without using blocking function in C++/C 如何使用 C++ 取消线程? - How can I cancel a thread using C++? 在不使用C ++ STL的情况下将字符串从函数中反转后如何返回? - How can i return a string after reversing it from a function in without using the C++ STL? 如何在不使用 C++ 函数的情况下显示链表中的元素? - How can I display elements in the linked list without using function in C++? 在 C++ 中,std::thread 如何在不创建 object 的情况下调用成员 function? - In C++, How a std::thread can call a member function without creating an object? 我如何从C ++中的静态线程入口点函数调用另一个函数? - How can i call an other function from static Thread entry point function in c++?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM