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. 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.
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.
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. You should use Linux event interface to distinguish between the two inputs. When some input is available from one of your hardwares, you can access it by reading a character devices under /dev/input/
directory. 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.
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.