简体   繁体   English

如何在C中的控制台中禁用箭头键

[英]How to disable arrow keys in console in C

I'm using the termios.h header file to implement a console in RAW mode and I'm trying to disable the arrow keys. 我正在使用termios.h标头文件在RAW模式下实现控制台,并且试图禁用箭头键。 I'm currently using the ctype.h file to test if the char I get from console is alphanumerical, however the up arrow is sent as the letter A. 我目前正在使用ctype.h文件来测试从控制台获取的字符是否为字母数字,但是向上箭头以字母A发送。

How do I disable the arrow keys. 如何禁用箭头键。

Thanks 谢谢

There were probably characters ahead of the A that were thrown out. A前面可能有一些字符被扔掉了。 You need to figure out what those characters were. 您需要弄清楚那些字符是什么。 The following code will help you figure out the sequence of characters that each arrow key generates. 以下代码将帮助您弄清楚每个箭头键生成的字符序列。 Once you know that, you can modify the code to ignore those sequences. 一旦知道,就可以修改代码以忽略这些序列。

int main( void )
{
    int c;

    while ( (c = getchar()) != EOF )
        printf( "%02x\n", c );
}

What you think to use libreadline? 您认为使用libreadline有什么用?

I use this library in a project where i build a console, and works so good. 我在构建控制台的项目中使用了此库,并且效果很好。 You can see the documentation here: http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html 您可以在此处查看文档: http : //cnswww.cns.cwru.edu/php/chet/readline/rltop.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM