为什么用getche()接受字符之后会在屏幕输出一个a啊?

qq_33186495 2015-12-10 01:21:29
求解释,还有为什么用getche接受输入 按下右方向键,键值是77啊,那剩下方向的键值是多少,为什么不是37,38等等
...全文
105 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2015-12-10
  • 打赏
  • 举报
回复
仅供参考:
//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);
    }
}
paschen 2015-12-10
  • 打赏
  • 举报
回复
#define VK_LEFT 0x25 #define VK_UP 0x26 #define VK_RIGHT 0x27 #define VK_DOWN 0x28

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧