![](/img/trans.png)
[英]“The C++ compiler ”/usr/bin/c++“ is not able to compile a simple test program.” When trying to install OpenCV
[英]Trying to set up a simple keyboard input in a c++ program. Using variables to store true or false
所以我不知道为什么我会遇到麻烦。 我环顾四周,但至今未找到答案。 许多人说你是cin
,但是很难创建一个布尔值来存储是否按下了一个键,并且它会暂停项目直到接收到输入。
我的理想设置是在更新循环中触发的一个函数,该函数存储是否在布尔变量中按下了键……类似这样:
bool left;
bool right;
bool up;
bool down;
Update()
{
Input();
}
Input()
{
//Insert code for detecting whether each of the keys is up or down
}
如果您能帮我解决这个问题,那就太好了! 另外,我的目标是制作一个基本上没有主要库(图形和数学除外)的程序,因此,如果只能使用很棒的c ++方法从头开始编写程序,但是如果程序过于复杂,则可以使用外部库。
另外,最好将鼠标x和y存储在其中。 我可以找出窗口部分(例如笛卡尔原点在哪里),但是我不知道如何访问鼠标。
您可以使用GetAsyncKeyState
确定是否按下了按键:
const bool up = GetAsyncKeyState(VK_UP);
const bool down = GetAsyncKeyState(VK_DOWN);
const bool left = GetAsyncKeyState(VK_LEFT);
const bool right = GetAsyncKeyState(VK_RIGHT);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.