Linux上的键盘键代码表

范思法兰

我正在学习C ++。

我正在测试如何按下哪个键。我写了这段代码:

#include <signal.h>
#include <termios.h>
#include <stdio.h>
#include <math.h>

#define KEYCODE_L 0x44 // Left Arrow Key
#define KEYCODE_R 0x43 // Right Arrow Key
#define KEYCODE_U 0x41 // Up Arrow Key
#define KEYCODE_D 0x42 // Down Arrow Key
#define KEYCODE_Q 0x71 // Q Key

int main(int argc, char **argv)
{
  // get the console in raw mode
  tcgetattr(kfd, &cooked);
  memcpy(&raw, &cooked, sizeof(struct termios));
  raw.c_lflag &= ~(ICANON | ECHO);

  // Setting a new line, then end of file
  raw.c_cc[VEOL] = 1;
  raw.c_cc[VEOF] = 2;
  tcsetattr(kfd, TCSANOW, &raw);

  puts("Reading from keyboard");
  puts("---------------------------");
  puts("Use arrow keys to move the robot.");

  // get the next event from the keyboard
  if (read(kfd, &c, 1) < 0)
  {
    perror("read():");
     /**
     * Reset console to its original mode.
     */
     tcsetattr(kfd, TCSANOW, &cooked);
     exit(-1);
  }

  switch (c)
  {
   case KEYCODE_R:
     std::cout << "Right Arrow" << std::endl;
      break;
   case KEYCODE_L:
     std::cout << "Left Arrow" << std::endl;
      break;
    case KEYCODE_U:
     std::cout << "Up Arrow" << std::endl;
      break;
    case KEYCODE_D:
     std::cout << "Down Arrow" << std::endl;
      break;
  }
}

在哪里可以找到我称为KEYCODE_的所有这些值的表?

我正在寻找一个包含所有键值的表。我找到了一个JavaScript表,但是值不匹配。

谢尔盖

这些是终端给您的Ascii代码。您可以通过showkey -a在Linux中使用命令来查看它们

有关此命令的更多信息,请参见手册页和联机手册,例如https://linux.die.net/man/1/showkey

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章