检查鼠标左键是否被单击时,GetKeyState 函数不起作用 [英] GetKeyState function not working when checking if left mouse button is clicked

查看:41
本文介绍了检查鼠标左键是否被单击时,GetKeyState 函数不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想看看鼠标左键是否被点击,如果是,它会输出 You clicked 我有这段代码,它会在你第一次点击时起作用.在那之后,我必须右键单击然后左键单击才能使其再次工作.如果我只是左键单击什么都不会发生.这是为什么?

I am trying to see if the left mouse button is clicked and if it is it will output You clicked I have this piece of code which will work the first time you click. After that though, I have to right click and then left click in order for it to work again. If I just left click nothing will happen. Why is this?

#include <iostream>
#include <windows.h>
using namespace std;

int main()
{
    while (true)
    {
        if (GetKeyState(VK_LBUTTON) < 0) {
            cout << "clicked" << endl;
        }
    }


}

推荐答案

在那之后,我必须按顺序右键单击然后左键单击让它再次工作.如果我只是左键单击什么都不会发生.为什么是这个?

After that though, I have to right click and then left click in order for it to work again. If I just left click nothing will happen. Why is this?

是的,我可以在单击控制台窗口的客户区域时重现此问题.

Yes, I can reproduce this issue when click on client area of the console window.

控制台编辑模式误导了我们.当您单击控制台窗口的客户区时,会使其进入编辑模式并且程序停止.要解决此问题,您可以取消选中快速编辑模式"选项(您可以通过单击控制台窗口左上方的图标找到它,然后选择属性"->选项"->编辑选项"),或单击在控制台窗口的标题栏上,而不是在客户区.

There is a console edit mode misleading us. When you click on client area of the console window, cause it enter edit mode and program stops. To solve this issue you can uncheck the "Quick Edit Mode" option (You can find it via click icon at left top of the console window then select Properties -> Options -> Edit Options), or click on title bar of the console window instead of on client area.

请检查您的情况.

这篇关于检查鼠标左键是否被单击时,GetKeyState 函数不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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