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. Catching mouse/key events outside the application
Qt 6.11 is out! See what's new in the release blog

Catching mouse/key events outside the application

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 4 Posters 4.4k Views 5 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.
  • A Offline
    A Offline
    Alper Karakus
    wrote on last edited by
    #1

    Hi,

    I need to catch system events outside an app like hooking keyboard presses and mouse events. I thought I could use the classes QMouseEvent and QKeyEvent as they are delivering events from the Windows system but It did not work.. Also tried to use the library named "LibQxt" but as the library does not have support for 5.5.1 MSVC 2013, I cannot use it for my app.

    Another thing is, I want to have this application cross platform :) What do you suggest me to do?

    Regards

    1 Reply Last reply
    0
    • E Offline
      E Offline
      Eligijus
      wrote on last edited by
      #2

      You could try this QPoint QCursor::pos().

      1 Reply Last reply
      1
      • kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by kshegunov
        #3

        http://doc.qt.io/qt-5/qwidget.html#grabKeyboard
        http://doc.qt.io/qt-5/qwidget.html#grabMouse

        But be careful with those, you might end up making your system pretty unusable if you fail to release the mouse and keyboard input.

        Read and abide by the Qt Code of Conduct

        A 1 Reply Last reply
        2
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          What is your goal catching keyboard and mouse outside from your application ?

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

          A 1 Reply Last reply
          1
          • SGaistS SGaist

            Hi,

            What is your goal catching keyboard and mouse outside from your application ?

            A Offline
            A Offline
            Alper Karakus
            wrote on last edited by
            #5

            @SGaist

            Hi. I'll add this capability to a widget object to be used in another Qt based software.

            @kshegunov , @Eligijus

            Thank you for your replies.

            1 Reply Last reply
            1
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Sounds like you should rather provide some sort of IPC mechanism between these two applications, no ?

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

              A 1 Reply Last reply
              1
              • SGaistS SGaist

                Sounds like you should rather provide some sort of IPC mechanism between these two applications, no ?

                A Offline
                A Offline
                Alper Karakus
                wrote on last edited by
                #7

                @SGaist

                Sadly no, not exactly. I'm in need of developing this as a widget object for a SCADA software. The widget object needs to get mouse and keyboard events from the system during the runtime of SCADA so the end user can reach the out of scope values/events like cursor position or key pressed etc... Some kind of IPC mechanism is also possible to be implemented for the situation maybe but I'm trying to develop the widget for the end user. So only the "event handling" part of widget better be accessed over GUI by the end user.

                When I use grabMouse(), do I need to install another eventFilter to the mouse object so it can work like a call back when cursor position is changed in out of scope?

                1 Reply Last reply
                0
                • kshegunovK kshegunov

                  http://doc.qt.io/qt-5/qwidget.html#grabKeyboard
                  http://doc.qt.io/qt-5/qwidget.html#grabMouse

                  But be careful with those, you might end up making your system pretty unusable if you fail to release the mouse and keyboard input.

                  A Offline
                  A Offline
                  Alper Karakus
                  wrote on last edited by
                  #8

                  @kshegunov said in Catching mouse/key events outside the application:

                  http://doc.qt.io/qt-5/qwidget.html#grabKeyboard
                  http://doc.qt.io/qt-5/qwidget.html#grabMouse

                  But be careful with those, you might end up making your system pretty unusable if you fail to release the mouse and keyboard input.

                  How can I get the mouse events after grabbing? Do I need to install another filter for it? After grabbing it still does not grab mouse move events outside the widget window.

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    AFAIK, the grabbing will only occur as long as you're on your application widget which as the grab mouse/keyboard activated otherwise it would mean that your application is spying on the mouse/keyboard while not being the active one.

                    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
                    0

                    • Login

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