Search code examples
ubuntueventsvirtual-machinevmwareevdev

Reading mouse/keyboard events on Virtual Machine(VM) Ubuntu


Basically I need to read mouse & keyboard events, so the program will know when you are pressing keys or scrolling.

It works fine on my physical machine, but does not show any events when I connect to virtual machine(VMware in my case) via Remmina VNC(from Ubuntu). Despite, both mouse and keyboard work as usual in VM. I have tried connecting to all available devices in /dev/input but still it's quiet. Then I tested all devices with evtest and got the same result - nothing.

I don't think, that it depends on my code, but I used this library.

Does it possible to achieve this? Maybe I missed something important? Any help, articles or links would be greatly appreciated.


UPDATE: I've recently tried a xinput:

xinput list

There were another devices, called Virtual core XTEST pointer and Virtual core XTEST keyboard that actually showed events with help of xinput test <ID>. These devices are not listed in /proc/bus/input/devices, so I have hope that will help.


Solution

  • So, I have implemented a listener for xinput with commands xinput test Virtual core XTEST pointer and xinput test Virtual core XTEST keyboard. As I have read from this article, each master device have a Virtual core XTEST....

    I am using QT, and code is looks like this:

    ...
    mouseProcess = new QProcess(this);
    mouseProcess->setProcessChannelMode(QProcess::MergedChannels);
    
    // Listen to output of process with function ReadOut()
    connect(mouseProcess, SIGNAL(readyReadStandardOutput()), SLOT(ReadOut()));
    mouseProcess->start("xinput", QStringList() << "test" << "Virtual core XTEST pointer");
    ...
    
    
    void ReadOutMouse() {
        QByteArray out = mouseProcess->readAllStandardOutput();
        QString output(out);
        if (output.contains("button press"))
            emit mouseEvent();
    }
    
    ...
    
    // The same is for Keyboard:
    void ReadOutKeyboard() {
        QByteArray out = keyboardProcess->readAllStandardOutput();
        QString output(out);
        if (output.contains("key release"))
            emit keyboardEvent();
    }