zoukankan      html  css  js  c++  java
  • 测试键盘的控制字符对应的ASCII码值

    #include <stdio.h>
    #include <termio.h>      //终端操作头文件

    char getch(void)
    {
         struct termios tm, tm_old;
         int fd = 0, ch;
     
         if (tcgetattr(fd, &tm) < 0) {    //保存现在的终端设置
              return -1;
         }
     
         tm_old = tm;
         cfmakeraw(&tm);    //更改终端设置为原始模式,该模式下所有的输入数据以字节为单位被处理
         if (tcsetattr(fd, TCSANOW, &tm) < 0) {    //设置上更改之后的设置
              return -1;
         }
     
         ch = getchar();
         if (tcsetattr(fd, TCSANOW, &tm_old) < 0) {    //更改设置为最初的样子
              return -1;
         }
        
         return (char)ch;
    }

    int main(void)
    {
        char ch;
        while((ch = getch()) != 0x0D && ch != 0x1B) {
            printf("%x", ch);
        }
        printf(" ");
        return 0;
    }

  • 相关阅读:
    交流课件
    ARC127F ±AB
    CF1566F xor-quiz
    JOISC 2016 Day 1 棋盘游戏
    dev分支和release是什么
    drf 笔记
    drf 序列化的写法 总结
    Linux系统编程
    C/C++ 网络编程
    C++提高编程
  • 原文地址:https://www.cnblogs.com/wanhuan/p/5847110.html
Copyright © 2011-2022 走看看