c语言怎么监视键盘,C语言键盘按键无阻塞侦测:kbhit()

kbhit in c

kbhit in c: kbhit function is used to determine if a key has been pressed or not. To use kbhit function in your program you should include the header file "conio.h". If a key has been pressed then it returns a

non zero value otherwise returns zero.

Declaration : int kbhit();

C programming code for kbhit

#include

#include

main()

{

while (!kbhit())

printf("You haven't pressed a key.");

return 0;

}

As long as in the above program user doesn't presses a key kbhit() return zero and (!0) i.e. 1 the condition in while loop is true and "You haven't pressed a key." will be printed again and again. As a key is pressed

from the keyboard the condition in while loop become false as now kbhit() will return a non-zero value and ( !(non-zero) = 0), so the control will come out of the while loop.

===========================

ubuntu上没有conio.h如何解决

www.MyException.Cn   发布于:2012-08-01 17:53:40   浏览:142次

本人用的ubuntu12.04版本,gcc是4.6.3版本,要下载什么样的conio.h和库文件?难道只能用ncurses替代吗

------解决方案--------------------------------------------------------

来自百度百科:

conio 库不仅适用于 Window 平台,在 Linux 下也可使用.网上已经有兼容包,下载后打开就可使用;而至于Mac则完全跟Window没有区别,直接可以使用.

------解决方案--------------------------------------------------------

自己没试过,希望对你有帮助,或者直接自己搜索关键字 "linux 使用 conio.h".

http://zhidao.baidu.com/question/241772898.html

http://tech.techweb.com.cn/thread-183749-1-1.html

------解决方案--------------------------------------------------------

用curses.h

------解决方案--------------------------------------------------------

sudo apt-get install libncurses5-dev

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值