在linux中如何用C语言实现读取“上下左右、ESC”键
来源:互联网 发布:淘宝速刷 编辑:程序博客网 时间:2024/05/18 03:59
s废话不多说,直接上代码!
#include <stdio.h>#include <string.h>#include <stdlib.h>//分配内存的大小#define SIZE 10//定义按键们的宏#define ESC "\033"#define UP "\033[A"#define DOWN "\033[B"#define LEFT "\033[D"#define RIGHT "\033[C"int main(){ char *get = (char*)malloc(SIZE); for ( ; ; ) { fgets(get, SIZE, stdin); /* 用fgets()函数从stdin中读取字符串时,会自动在字符串末尾追加"\n",这里将末尾字符改为"\0" */ get[strlen(get) - 1] = '\0'; if (!strcmp(get, ESC)) printf("This is \"ESC\" button!\n"); if (!strcmp(get, UP)) printf("This is \"UP\" button!\n"); if (!strcmp(get, DOWN)) printf("This is \"DOWN\" button!\n"); if (!strcmp(get, LEFT)) printf("This is \"LEFT\" button!\n"); if (!strcmp(get, RIGHT)) printf("This is \"RIGHT\" button!\n"); } return 0;}
运行效果如图:
0 0
- 在linux中如何用C语言实现读取“上下左右、ESC”键
- 最近在研究如何用C语言实现AI
- 如何用drawtext在linux系统中开发实现中文字幕
- 如何用c语言实现多态
- 如何用C语言实现面向对象
- 如何用C语言实现三子棋游戏
- C语言中如何用printf 和scanf来处读取和输出各种数据
- 如何用c读取文件
- 在c语言中如何用数组处理求Fibonacci数列问题
- C语言如何用OpenGL
- C语言如何用OpenGL
- 如何用C语言实现类似C++中的多态
- 如何用C语言实现带参数的dos命令?
- 【C语言】如何用递归的方法实现n^k
- 如何用C语言实现圈叉游戏(-)
- linux下如何用c语言调用shell命令
- linux下如何用c语言调用shell命令
- linux下如何用c语言调用shell命令
- 平衡二叉树(AVL树)深入解读
- HDU 3496 dp
- UVALive-7278 - Game of Cards【博弈】【sg定理】
- L2-011. 玩转二叉树-PAT团体程序设计天梯赛GPLT
- Windows下本机SSH的生成
- 在linux中如何用C语言实现读取“上下左右、ESC”键
- InvalidateRect function
- GDB详解
- Unity Mecanim动画的实现(三):Animation编辑之Root Motion
- 测试经理、自动化测试工程师工作指导书
- leetcode_c++:Add Binary(067)
- 2016多校训练#1 1002 组合博弈
- 曼哈顿距离最小生成树
- extern用法总结