简体   繁体   English

使用eventfilter区分2个键盘击键(嵌入式linux)

[英]distinguish 2 keyboards keystrokes using eventfilter (embedded linux)

I know there has been a few topics similar to this one, they don't ask exactly the same question and their answers are not what I need. 我知道有几个主题与此主题类似,他们并没有提出完全相同的问题,他们的答案也不是我所需要的。 I will try to explain briefly my situation. 我将尝试简要地解释我的情况。

I have two keyboards, one is standard USB keyboard (HID), the other is a GPIO keyboard. 我有两个键盘,一个是标准USB键盘(HID),另一个是GPIO键盘。 There are keys commonly reported by both keyboards but I need to take different actions in my Qt application depending on by which keyboard the key was pressed. 两个键盘通常都报告有键,但是我需要在Qt应用程序中采取不同的操作,具体取决于按下哪个键盘的键。

At this moment both keyboards work fine at the same time, but I just can't find a way to identify from which keyboard comes the pressed key. 目前,两个键盘都可以同时正常工作,但我只是找不到一种方法来识别按下的键盘来自哪个键盘。

Is this even possible? 这有可能吗? I'm, using Qt 4.8.5 and I can recompile it in case it is needed to accomplish what I need. 我正在使用Qt 4.8.5,可以重新编译它,以防需要完成我所需要的。

Any help, hint, tip will be highly appreciated. 任何帮助,提示,技巧将不胜感激。

Thank you for the help, 感谢您的帮助,

William 威廉

Qt does not have this feature to detect which keyboard is pressed. Qt没有此功能来检测按下哪个键盘。 You should use Linux event interface to distinguish between the two inputs. 您应该使用Linux事件接口来区分两个输入。 When some input is available from one of your hardwares, you can access it by reading a character devices under /dev/input/ directory. 当可以从其中一种硬件获得某些输入时,可以通过读取/dev/input/目录下的字符设备来访问它。 For instance you have probably a file like /dev/input/by-id/usb-0b38_0010-event-kbd which could be read to see the input from the specific keyboard. 例如,您可能有一个文件,例如/dev/input/by-id/usb-0b38_0010-event-kbd ,可以读取该文件以查看特定键盘的输入。

You can read the specific files for the two keyboards in two separate threads and each time you read some new data from one of them, send a signal to your main thread to notify that the input is from which of the keyboards : 您可以在两个单独的线程中读取两个键盘的特定文件,并且每次从其中一个读取一些新数据时,都向主线程发送信号,以通知输入来自哪个键盘:

In the first thread : 在第一个线程中:

QFile file("/dev/input/by-id/FileForKeyboard1");

if(file.open( QIODevice::ReadOnly | QIODevice::Text ) )
{
    QTextStream stream( &file );
    while(true)
    {
        stream.read(1);
        emit keyBoard1_Pressed();
    }
}

In the second thread : 在第二个线程中:

QFile file("/dev/input/by-id/FileForKeyboard2");

if(file.open( QIODevice::ReadOnly | QIODevice::Text ) )
{
    QTextStream stream( &file );
    while(true)
    {
        stream.read(1);
        emit keyBoard2_Pressed();
    }
}

Note that you should have root access to read from the these files. 请注意,您应该具有root用户访问权限才能读取这些文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C ++-使用SendInput方法模拟击键,无法区分rightctrl键 - C++ - Simulating keystrokes using SendInput method, failure to distinguish rightctrl key "<i>How to get keyboard name?<\/i>如何获取键盘名称?<\/b> <i>(to visually distinguish keyboards in a specific language)<\/i> (在视觉上区分特定语言的键盘)<\/b>" - How to get keyboard name? (to visually distinguish keyboards in a specific language) 我们可以在 Linux 中使用 C++ 使用原始 ASCII 值生成击键吗? - Can we generate keystrokes using a raw ASCII values using C++ in Linux? 需要帮助以使用C ++在Linux环境中生成对现有应用程序的击键 - need help to generate keystrokes into existing application in Linux environment using C++ 访问Linux中C ++(或python)输入的多个键盘 - Accessing multiple keyboards input by C++ (or python) in linux 在嵌入式Linux平台上使用std :: string时出现段错误 - Seg Fault when using std::string on an embedded Linux platform 在嵌入式Linux上使用C ++ Std Lib时出现异常的段错误 - Unusual segfault when using C++ Std Lib on embedded Linux linux发行版用于嵌入式开发? - linux distro for Embedded development? 内存泄漏和嵌入式Linux - Memory leaking and embedded linux 嵌入式Linux上的轻量级调试 - Lightweight debugging on embedded Linux
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM