检测鼠标按钮是否按下 [英] Detect if mouse button is down

查看:380
本文介绍了检测鼠标按钮是否按下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是c ++的新手,我试图仅在按住鼠标左键时激活一行代码 only .在此示例中,我的代码有效,但似乎只是对其进行了切换.当我单击时,它会向 H 键发送垃圾邮件,然后,当我再次单击时,它将停止.

I am new to c++ and I am trying to activate a line of code only when the left mouse button is held down. In this example, my code works but it seems that it just toggles it. When I click, it spams the H key then, when I click again, it stops.

当前我有以下代码:

if ((GetKeyState(VK_LBUTTON)))
{
    keybd_event(VkKeyScan('H'),0,0,0);
    Sleep ( 30 );
}

我在函数内部:

int WINAPI WinMain ( HINSTANCE hInst, HINSTANCE P, LPSTR CMD, int nShowCmd );

推荐答案

使用它来确定是否按下了按钮.

Use this to determine if the button is pressed.

if((GetKeyState(VK_LBUTTON) & 0x100) != 0)

http://vcpptips.wordpress.com/tag/vk_lbutton/

这篇关于检测鼠标按钮是否按下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆