在 Linux 终端应用程序中接收按键按下和按键释放事件? [英] Receiving key press and key release events in Linux terminal applications?

查看:42
本文介绍了在 Linux 终端应用程序中接收按键按下和按键释放事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个简单的 C 程序,该程序将根据按下键"和按下键"事件执行不同的操作.该程序将从 rxvt 内部运行.

I would like to write a simple C program that will perform different actions based on both "key down" and "key up" events. This program will be run from inside rxvt.

我应该使用什么库或机制来访问按键和释放?阅读 /dev/tty 是否真的只会提供关键版本?这对 termcap、terminfo、ncurses 和俚语也是如此吗?有没有办法从终端应用程序中实现这一点?

What library or mechanism should I use to access both key presses and releases? Is it true that reading /dev/tty will only provide key releases? Is this also true for termcap, terminfo, ncurses, and slang? Is there a way to achieve this from within a terminal application?

推荐答案

以下链接可能对使用键盘原始模式有所帮助,该模式将使您能够访问键盘事件,而不仅仅是按键释放.

The following links may be of some assistance in using the keyboard raw mode which will give you access to the keyboard events rather than just key releases.

  1. 这篇 Linux 期刊 文章
  2. 这篇关于 SourceForge 的文章
  3. 还有这个 HOWTO 当一切都变坏时
  1. This Linux Journal article
  2. This article on SourceForge
  3. And this HOWTO for when it all goes bad

Raw 模式确实有一个缺点,即您必须自己进行从扫描码到字符的转换.

Raw mode does have the disadvantage that you have to do your own conversion from scan codes to characters though.

这篇关于在 Linux 终端应用程序中接收按键按下和按键释放事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆