C ++,监视键盘输入 [英] C++, monitor for keyboard input

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

问题描述

我正在刷新我的一般编程技能,我遇到了一个障碍。我在写一个程序,模拟一群bunnys。一旦这个程序启动,它是自主的,然而,在任何点,用户应该能够按k键剔除人口一半。我不能想办法做到这一点,而不暂停程序等待用户输入。我也不能想到一种方法使程序将立即响应(程序使用sleep命令半实时运行)。有没有办法做到这一点没有多踩和多年的经验?

I'm brushing up on my general programing skills and I've come across a snag. I'm writing a program that simulates a colony of bunnys. Once this program starts it is autonomous, however, at any point the user should be able to press the 'k' key to cull the population by half. I can't think of a way to do this without pausing the program to wait for user input. Nor can I think of a way to make it so that the program will respond immediately (the program runs in semi-real time using the sleep command). Is there a way to accomplish this without multi-treading and years more experience?

推荐答案

我认为这文章接近您想要的内容不涉及ncurses。

I think this article comes close to what you want to do w/o involving ncurses.

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

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