Not able to read /dev/input/mice
-
Hi all,
I am trying to get information about mouse events.
Therefore I did the following:... void MyClass::init(void) { m_file = new QFile("//dev/input/mice"); if (!m_file->open(QIODevice::ReadWrite)) { } else { m_notifer = new QSocketNotifier(m_file->handle(), QSocketNotifier::Read, this); connect(m_notifer, SIGNAL(activated(int)), this, SLOT(readMouseData(int))); } } ... void MyClass::readMouseData(int socket) { QByteArray mouseData = m_file->readAll; } ...
If I click or move the mouse, the socket notifier calls readMouseData().
But then I have the problem that all hangs up at readAll(). readAll() does not return.
Does anyone know what the problem is? -
Since it's not a regular file some methods might not work. Check the docs, it's usually explained there.
Try connecting a data stream to it and reading it this way.
-
Does using the QIODevice::readyRead() signal not work on this?
Observations:
- The path is
/dev/input/mice
which may cause issue. - An unprivileged user will not be able open this file on many systems (My Ubuntu machine for example).
- You are not likely to to write to this file, so why open ReadWrite?
- The path is
-
Does using the QIODevice::readyRead() signal not work on this?
Observations:
- The path is
/dev/input/mice
which may cause issue. - An unprivileged user will not be able open this file on many systems (My Ubuntu machine for example).
- You are not likely to to write to this file, so why open ReadWrite?
- The path is
-
@ChrisW67
Purely OoI, without sidetracking topic so briefly, what exactly is/dev/input/mice
and what's it for anyway? :) [Not to mention, how many multiple mouses are supposed to be attached?]@JonB if memory serves well, it's a "multiplexer" device that is to be considered a hack to be used by older applications. It's a permanent device that gets the signals from the other mouse/tablet devices. Useful in the case of mouse hot plugin for applications that cannot handle them.
-
Does using the QIODevice::readyRead() signal not work on this?
Observations:
- The path is
/dev/input/mice
which may cause issue. - An unprivileged user will not be able open this file on many systems (My Ubuntu machine for example).
- You are not likely to to write to this file, so why open ReadWrite?
- I did not try QIODevice::readyRead()
- I corrected the path to "//dev/input/mice"
- User has privilges. The user belongs to the group input.
- ReadWrite-access is not necessary. I used it during my tries to get it run. I changed it back to readOnly.
- The path is
-
Now it is working.
If someone is interested, here are the code snippets:... void MyClass::init(void) { m_file = new QFile(); m_file->setFileName(m_filename); if (!m_file->exists()) { qWarning("file does not exist"); return false; } else { m_fd = open(m_filename.toUtf8().data(), O_RDONLY|O_NONBLOCK); if(m_fd==-1) { qWarning("can not open file"); return false; } else { m_notifier = new QSocketNotifier(m_fd, QSocketNotifier::Read, this); connect(m_notifier, &QSocketNotifier::activated, this, &MyCursor::readMouseData); return true; } } } ... void MyClass::readMouseData(int socket) { qDebug() << "***** readMouseData() *****"; } ...
-
Now it is working.
If someone is interested, here are the code snippets:... void MyClass::init(void) { m_file = new QFile(); m_file->setFileName(m_filename); if (!m_file->exists()) { qWarning("file does not exist"); return false; } else { m_fd = open(m_filename.toUtf8().data(), O_RDONLY|O_NONBLOCK); if(m_fd==-1) { qWarning("can not open file"); return false; } else { m_notifier = new QSocketNotifier(m_fd, QSocketNotifier::Read, this); connect(m_notifier, &QSocketNotifier::activated, this, &MyCursor::readMouseData); return true; } } } ... void MyClass::readMouseData(int socket) { qDebug() << "***** readMouseData() *****"; } ...
@MHermann
At one point you asked about the data/struct
returned when you read from/dev/input/mice
, though you seem to have removed that question now. Did you see e.g. https://stackoverflow.com/a/23317086, which seems to show it generates "messages" which are 3 bytes long? Or there is astruct input_event
in#include <linux/input.h>
? There is also a suggestion that nowadays you are supposed to use/dev/input/event#
instead, but I leave it to you.