# ersh_keyboard **Repository Path**: arrco/ersh_keyboard ## Basic Information - **Project Name**: ersh_keyboard - **Description**: 一个用于从 linux 终端获取按键的简易程序。 - **Primary Language**: C - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-10-06 - **Last Updated**: 2023-02-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # ersh_keyboard ## 介绍 ersh_keyboard 是一个用于从 linux 终端获取按键的简易程序。 按键的支持情况受到不同平台终端的影响,部分按键会不支持,可以根据需要自行修改或者添加。 ## 使用说明 只需要包含 `ersh_keyboard.c` 和 `ersh_keyboard.h` 两个文件即可使用。 ## 接口函数 提供以下接口用于获取键盘输入情况: ```c /* 键盘读取初始化 */ void ersh_keyboard_init(void (*callback)(int)); /* 键盘读取轮询函数 */ void ersh_keyboard_poll(void); ``` ## 接口使用说明 ### 1.键盘读取初始化 调用接口`ersh_keyboard_init`初始化程序。 ```c /* 键盘读取初始化 */ void ersh_keyboard_init(void (*callback)(int)); ``` 函数参数含义: | 参数 | 含义 | | -------- | ---------------------- | | callback | 接收按键事件的回调函数 | 函数返回值: | 返回值 | 含义 | | ------ | ---- | | 无 | 无 | ### 2.键盘读取轮询函数 调用接口`ersh_keyboard_poll`进行轮询查询按键输入情况。 ```c /* 键盘读取轮询函数 */ void ersh_keyboard_poll(void); ``` 函数参数含义: | 参数 | 含义 | | ---- | ---- | | 无 | 无 | 函数返回值: | 返回值 | 含义 | | ------ | ---- | | 无 | 无 | ## 配置使用说明 ### 1.支持`CTRL-C`和`CTRL-Z` 支持`CTRL-C`和`CTRL-Z`输入。 ### 2.支持`CTRL-S`和`CTRL-Q` 支持`CTRL-S`和`CTRL-Q`输入。 ### 3.支持`CTRL-V` 支持`CTRL-V`输入。 ### 4.支持`CTRL-M` 支持`CTRL-M`输入。 ## 使用示例 基础程序用法: ```c void printf_val(int key) { if(key < 32) { printf("%d\r\n", key); } else if(key < 128) { printf("%d %c\r\n", key, key); } else { printf("%d\r\n", key); } } int main(int argc, char* argv[]) { ersh_keyboard_init(printf_val); while(1) { ersh_keyboard_poll(); } return 0; } ``` 按下按键`a`, `b`, `c`, `d`, `1`, `2`, `3`, `4`运行结果如下: ``` 97 a 98 b 99 c 100 d 49 1 50 2 51 3 52 4 ``` ## License MIT License Copyright (c) 2022 Hong Jiahua Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.