在 Linux 终端应用程序中接收按键按下和按键释放事件

发布于 2024-08-04 15:23:23 字数 543 浏览 4 评论 0原文

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

我应该使用什么库或机制来访问按键和释放?读取 /dev/tty 真的只会提供关键版本吗? termcap 也是如此吗? org/wiki/Terminfo" rel="nofollow noreferrer">terminfo, ncursesS-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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

七婞 2024-08-11 15:23:23

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

  1. 这篇 Linux 期刊文章
  2. 这篇SourceForge 上的文章
  3. 还有这个 HOWTO 当一切都变坏时

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

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. This Linux Journal article
  2. This article on SourceForge
  3. 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.

混吃等死 2024-08-11 15:23:23

这在一般情况下不起作用。 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.

扮仙女 2024-08-11 15:23:23

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文