上检测keydown和keyup事件

上检测keydown和keyup事件

本文介绍了在Linux C ++上检测keydown和keyup事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检测和时间戳每一个keydown和keyup事件在一个程序(是的,我的意思是键盘和键盘不只是按键)以及按下了什么键。我可以通过使用像GTK这样的APi来做到这一点,但是我想要尽可能简单和低级,以避免图书馆影响时间的开销以及编写更少的代码。

I want to detect and time stamp every keydown and keyup event in a program (Yes, I mean keydown and keyup not just keypress) along with what key was pressed. I could do this by using an APi such as GTK, but I want to get as simple and low level as possible in order to avoid overhead from the libraries affecting the times as well as writing less code.

我已经在谷歌搜索了一段时间,到目前为止,已经发现了一大堆关于如何在Windows上做的事情,这不利于我,因为我使用Linux系统,以及如何检测在Linux上的一个按键,但不是keyup keydown。

I have been googling this for a while and so far have found a ton of stuff about how to do it on Windows, which doesn't help me since I am using a Linux system, and how to detect a key press on Linux, but not keyup keydown.

任何人都可以告诉我需要使用什么系统调用,库等才能捕获keydown和keyup使用C ++中的命令行程序在Linux系统上的事件?如果您有教程或代码示例的链接,那将是非常感谢。

Can anyone tell me what syscall, library, etc. I would need to use in order to capture the keydown and keyup events on a Linux system with a commandline program in C++? And if you have a link to a tutorial or a code example it would be most appreciated.

推荐答案

实际上,你不是没有图书馆就能做到这一点。如果你想要的开销很少,我建议 ncurses 。如果您绝对必须在没有库的情况下执行,请查看ncurses如何实现它。当然,这将非常复杂。

Realistically, you aren't going to be able to do this without a library. If you want something that has very little overhead, I would suggest ncurses. If you absolutely must do it without a library, look at how ncurses implements it. It will, of course, be very complicated.

这篇关于在Linux C ++上检测keydown和keyup事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 08:44