关于方向键up的问题(我感觉很怪,和ascll码不一样)
int getkey()
{
int key,lo,hi;
key=bioskey(0);
lo=key&0x00ff;
hi=(key&0xff00)>>8;
return((lo==0) ? hi+256:lo);
}
当我输入up键时,key的数值,我感觉很怪异:一%x输出时4800,以%d输出时时18432;
但是我看ascll码表,上面up的值不是这样的呀!
[解决办法]
ASCII是一套信息传输人编码,理论上跟硬件没有任何关系;而键盘扫描码跟“键盘”这一硬件设备是直接对应的,他们原本就不一样啊。
另外ASCII码中有UP吗?我怎么没找到?
http://www.asciitable.com/
[解决办法]
//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); }}