简体   繁体   English

使用C ++睡眠特定的鼠标移动

[英]Sleeping a specific mouse movement with C++

I'm trying to control the mouse movement in an application, so far I'm using HWND GetActiveWindow with PostMessage, it works fine but I want to add a little bit of delay. 我正在尝试控制应用程序中的鼠标移动,到目前为止我正在使用带有PostMessage的HWND GetActiveWindow,它工作正常,但我想添加一点延迟。 I added Sleep() and it's working as expected, sleeping the Active Window for X.. ms. 我添加了Sleep(),它正如预期的那样工作,睡眠活动窗口为X .. ms。

My question is, is there a way I can make the Sleep function to be triggered only when I click on a specific mouse button and then stop it immediately, or something close to this? 我的问题是,有没有办法只有当我点击一个特定的鼠标按钮然后立即停止它,或者接近这个时,我才能触发睡眠功能? Thank you, appreciate all your help. 谢谢你,感谢你的帮助。

You need to call the Sleep() function only when a specific mouse button is pressed: 只有在按下特定的鼠标按钮时才需要调用Sleep()函数:

UINT button = GET_XBUTTON_WPARAM(wParam);  
if (button == XBUTTON1)
{
    Sleep(1000);
}

See also: https://docs.microsoft.com/en-us/windows/desktop/inputdev/mouse-input 另请参阅: https//docs.microsoft.com/en-us/windows/desktop/inputdev/mouse-input

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM