C ++,如何用键盘输入控制程序流 [英] C++, how to control program flow with keyboard input

查看:183
本文介绍了C ++,如何用键盘输入控制程序流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主程序无限循环。通过使用键盘输入更改bool变量,我想能够控制是否在该循环中的某些if {}语句被调用。我找到此主题:

C非阻塞键盘输入

,但似乎过于费力和复杂的看似基本的功能。有更简单的方法吗?

I have a main routine that loops infinitely. By changing bool variables using keyboard input, I want to be able to control whether certain if{} statements within that loop are getting called. I found this thread:
C non-blocking keyboard input,
but it seems excessively laborious and complicated for seemingly basic functionality. Is there an easier way to do it?

推荐答案

你必须使用操作系统/获取输入事件,或使用为您执行此操作的库。无论如何,在C ++中没有内置的方法。

You'll have to use the OS/Firmware/Framework/environment API to get input events, or use a library that do this for you. Anyway, there is no built-in way of doing this in C++.

我经常使用 OIS 。它是跨平台和易于使用。不确定它在其他情况下比游戏有用,但它为你的工作。

I often use OIS in games. It's cross-platform and easy to use. Not sure it's useful for other cases than games but it does the job for you.

这篇关于C ++,如何用键盘输入控制程序流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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