在 Linux 终端应用程序中接收按键按下和按键释放事件
我想编写一个简单的 C 程序,它将根据“按下键”和“按下键”事件执行不同的操作。该程序将从 rxvt 内部运行。
我应该使用什么库或机制来访问按键和释放?读取 /dev/tty
真的只会提供关键版本吗? termcap 也是如此吗? org/wiki/Terminfo" rel="nofollow noreferrer">terminfo, ncurses和S-Lang?有没有办法从终端应用程序中实现这一点?
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.
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 S-Lang? Is there a way to achieve this from within a terminal application?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
以下链接可能会对使用键盘原始模式有所帮助,该模式将使您能够访问键盘事件而不仅仅是按键释放。
原始模式确实有一个缺点,即您必须自己进行从扫描代码到字符的转换。
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.
Raw mode does have the disadvantage that you have to do your own conversion from scan codes to characters though.
这在一般情况下不起作用。 ANSI 终端(所有仿真器均源自该终端)仅代表按键“按下”事件。他们不独立记录向下/向上事件。
如果您需要低级键盘事件访问,那么正确的环境实际上是 GUI 程序。即使是 Web 应用程序也比终端能够更清晰地访问关键事件。
This won't work in the general case. ANSI terminals (from which all emulators descend) represent key "press" events only. They don't record down/up events independently.
If you need low level keyboard event access, the proper environment is really a GUI program. Even a web application will have cleaner access to key events than a terminal.
我认为 ncurses 不会起作用。链接提供了Basilevs谈论的是“向上箭头”键和“向下箭头”键,而不是按键按下和释放。
I don't think ncurses will work. The link Basilevs provided talks about the "up arrow" key and the "down arrow" key, not a key press and release.