重点pressed和C键,释放中断 [英] Key pressed and key released interrupts in C

查看:190
本文介绍了重点pressed和C键,释放中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法赶在 KEY preSSED 键释放事件,而(1)环路从一个终端窗口中运行Linux的简单的C程序。

Is there a way to catch the KEY PRESSED and KEY RELEASED events in while (1) loop in simple C program on Linux running from a terminal window.

的kbhit()将返回真正如果某个关键是pressed,残培()返回是pressed的字符。

kbhit() will return true if a key was pressed, getch() returns the character that was pressed.

我如何赶上释放事件?

推荐答案

您不能在一个可移植的方式做到这一点。终端(以及那些如的xterm 的仿真器)只给你这是$ P的关键$ pssed,而不是释放事件。图形用户界面通常提供接受单独的preSS-和释放事件的能力。

You cannot do this in a portable manner. Terminals (and emulators of those such as xterm) give you only the key that was pressed, not the release events. Graphical user interfaces often provide the ability to receive separate press- and release-events.

在图形环境中运行的终端模拟器组成这些事件为单个字符。由于在图形环境看,那些都是的键符号的,其中可能包含的字符的。除了preSS-和释放事件的关键事件本身,你可以的修饰的如SHIFT-,控制和元改性剂是独立的事件。如果你运行 xev的 ,可以看到这些独立的事件。

Terminal emulators running in a graphical environment compose those events into individual characters. As read in the graphical environment, those are key symbols, which may contain characters. In addition to the press- and release-events for the key events themselves, you can have modifiers such as shift-, control- and meta-modifiers which are separate events. If you run xev, you can see these separate events.

撰写这些事件变成了一个角色之后,终端仿真器可以将其发送到您的应用程序在UTF-8编码的一系列数据字节,例如。当您使用 残培() ,ncurses库读取这些字节,并再次把它连成一个字符。在这两个(终端仿真程序和应用程序)之间是伪终端的及其的翻译,这两个终端仿真程序和应用程序必须处理。

After composing these events into a character, the terminal emulator may send it to your application as a series of data bytes, e.g., in UTF-8 encoding. When you use getch(), the ncurses library reads those bytes, and puts it together again into a character. In between those two (the terminal emulator and application) are the pseudo-terminal and its translation, which both terminal emulator and application must manipulate.

如果你的不可以在图形环境中运行,有(不总是)等方面比图形应用程序,如 xev的可以读直接的关键preSS /释放事件。在Linux控制台支持。例如,见的 接收Linux终端应用的关键preSS和键释放事件? <引用链接/ EM>

If you are not running in a graphical environment, there are (not always) other ways than graphical applications such as xev which can read directly the key press/release events. The Linux console supports that. See for example the links cited in Receiving key press and key release events in Linux terminal applications?

这篇关于重点pressed和C键,释放中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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