I am creating a cross-platform application in Qt5.15 monitoring user activity. My code works fine in Windows,Mac, and Raspberry Pi-Desktop-version(Debian), but when it comes to ubuntu keyboard events and mouse click events are not working. Note that my application is running in the background while the user is working.
#define MOUSEFILE "/dev/input/event4"
#define MOUSEMOVEFILE "/dev/input/js1"
#define KEYBOARDFILE "/dev/input/event0"
Header files included
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <linux/input.h>
#include <linux/input-event-codes.h>
#include <fcntl.h>
For keyboard event code
class KeyboardHook:public QThread
{
Q_OBJECT
void run() override
{
int fd;
struct input_event ie;
if((fd=open(KEYBOARDFILE,O_RDONLY))==-1)
{
//qDebug()<<"opening device";
exit (EXIT_FAILURE);
}
while(read(fd,&ie,sizeof(struct input_event)))
{
// qDebug()<<"Keyboard Activity";
if(ie.code==EV_KEY)
{
DateAndTime::s_previousActivity=QDateTime::currentDateTime();
GlobalHook::timeNow.start();
}
msleep(500);
}
}
};
But mouse-move is working. The code is same only difference KEYBOARDFILE is replaced with MOUSEMOVEFILE and NOT using below if statement
if(ie.code==EV_KEY)
If I don't use above checks for the keyboard I am getting continuous keyboard activity, even if the keyboard is not being touched.
The above code is working correctly in Debian.
when typing
ls -la /dev/input/by-id and ls -la /dev/input/by-path
When typing xinput
i am getting
My ubantu is installed in virtual-box