跟往常一样由于机械臂不支持ROS开发,不管实现什么功能都要自己写。
今天从一个视频获得启发,为了便于调试机械臂,用GPT写了一段电脑键盘按键调试的代码。
方法一:使用ncurses库实现
安装ncurses库
sudo apt-get install libncurses5-dev libncursesw5-dev
创建key_test.cpp文件
GPT给出的代码如下:
#include <ncurses.h>
#include <iostream>
int main() {
initscr(); // 初始化ncurses模式
cbreak(); // 禁用行缓冲,直接传递按键给程序
noecho(); // 关闭回显
printw("Press any key to see its ASCII value, ESC to exit\n");
int ch;
while ((ch = getch()) != 27) // 27是ESC键的ASCII值
{
printw("Key Pressed: %c, ASCII: %d\n", ch, ch);
refresh(); // 刷新屏幕以显示输出
}
endwin(); // 退出ncurses模式
return 0;
}
编译时链接ncurses库
GPT给出的g++编译命令如下:
g++ your_program.cpp -lncurses -o your_program
具体到本文使用的命令如下:
g