在Linux终端应用程序中接收按键和按键释放事件吗? [英] Receiving key press and key release events in Linux terminal applications?
问题描述
我想编写一个简单的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和slang也是这样吗?有没有一种方法可以从终端应用程序中实现?
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.
- This Linux Journal article
- This article on SourceForge
- And this HOWTO for when it all goes bad
原始模式确实有一个缺点,那就是您必须自己进行从扫描代码到字符的转换.
Raw mode does have the disadvantage that you have to do your own conversion from scan codes to characters though.
这篇关于在Linux终端应用程序中接收按键和按键释放事件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!