首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

键盘响应,该如何处理

2012-03-21 
键盘响应VS 2010里面关于接受键盘按键的函数是哪个啊??求高手指教。[解决办法]C/C++ code//The _getch func

键盘响应
VS 2010里面关于接受键盘按键的函数是哪个啊??求高手指教。

[解决办法]

C/C++ code
//The _getch function reads a single character from the console without echoing.//Function can not be used to read CTRL+Break.//When reading a function key or an arrow key,//_getch must be called twice; the first call returns 0 or 0xE0,//and the second call returns the actual key code.#include <conio.h>#include <windows.h>void main() {    unsigned short k;    while (1) {        Sleep(100);        k=getch();        if (27==k) break;//按Esc键退出        if (0==k||0xe0==k) k|=getch()<<8;//非字符键        cprintf("%04x pressed.\r\n",k);    }} 

热点排行