Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Not able to read /dev/input/mice
Forum Updated to NodeBB v4.3 + New Features

Not able to read /dev/input/mice

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 5 Posters 871 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MHermann
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      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.

      (Z(:^

      1 Reply Last reply
      1
      • C Offline
        C Offline
        ChrisW67
        wrote on last edited by
        #3

        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?
        JonBJ M 2 Replies Last reply
        4
        • C ChrisW67

          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?
          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @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?]

          SGaistS 1 Reply Last reply
          0
          • JonBJ JonB

            @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?]

            SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @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.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1
            • C ChrisW67

              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?
              M Offline
              M Offline
              MHermann
              wrote on last edited by
              #6

              @ChrisW67:

              • 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.
              1 Reply Last reply
              0
              • M Offline
                M Offline
                MHermann
                wrote on last edited by MHermann
                #7

                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() *****";
                }
                ...
                
                JonBJ 1 Reply Last reply
                0
                • M MHermann

                  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() *****";
                  }
                  ...
                  
                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #8

                  @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 a struct 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.

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved