跨平台的检测键盘是否有键按下并返回按键的值
2013-11-24 09:27
295 查看
/** * @return 0:没有按键按下 * 其他:有键按下,返回键的值 */ int GetCharIfKbhit(void); #ifdef _WINDOWS_ #include <conio.h> int GetCharIfKbhit(void) { int res = _kbhit(); if(res) res = _getch(); return res; } #else #include <termios.h> #include <fcntl.h> int GetCharIfKbhit(void) { struct termios oldt, newt; int ch; int oldf; tcgetattr(STDIN_FILENO, &oldt); newt = oldt; newt.c_lflag &= ~(ICANON | ECHO); tcsetattr(STDIN_FILENO, TCSANOW, &newt); oldf = fcntl(STDIN_FILENO, F_GETFL, 0); fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK); ch = getchar(); tcsetattr(STDIN_FILENO, TCSANOW, &oldt); fcntl(STDIN_FILENO, F_SETFL, oldf); return ch; } #endif
相关文章推荐
- 驱动中获取PsActiveProcessHead变量地址的五种方法
- 驱动中获取PsActiveProcessHead变量地址的五种方法
- svn不能添加.a文件的解决方法
- M,BB面试+职业求教
- jQuery页面滚动图片等元素动态加载实现
- 使用安卓手机连接win7的热点
- WIN API 调用
- php邮箱验证
- Linux下.run文件的安装和卸载
- Oracle之字符操作函数(认证考试指南)
- dede 留言簿相关使用
- Windows Server 2012 之开启和关闭GUI
- VC导出CListCtrl数据到Excel两种方法
- pet
- Creating a View Class//建立视图类
- 知识积累
- Cocos2d-x使用CCAnimation小实验——显示植物大战僵尸中的植物和僵尸
- eclipse 自动生成代码注释template
- XML三部曲之拨云见日DTD(二)
- Apache 的代理使用 配置