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. See if a key was presssed
Forum Updated to NodeBB v4.3 + New Features

See if a key was presssed

Scheduled Pinned Locked Moved Solved General and Desktop
17 Posts 4 Posters 1.3k Views 1 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.
  • S Offline
    S Offline
    Sucharek
    wrote on last edited by
    #1

    Hi, I have a problem. I need to "watch" to keyboard, to see, if whatever key was pressed globally, not just in the app, but globally.
    Is this possible? I have this, but it only picks up keys like shift, alt, caps lock, f keys, but not letters or numbers:

    void MainWindow::keyPressEvent(QKeyEvent *event) //included in .h file under the private category
    {
        if (event->KeyPress) {
            qDebug() << "key";
        }
    }
    
    JonBJ 1 Reply Last reply
    0
    • S Sucharek

      Hi, I have a problem. I need to "watch" to keyboard, to see, if whatever key was pressed globally, not just in the app, but globally.
      Is this possible? I have this, but it only picks up keys like shift, alt, caps lock, f keys, but not letters or numbers:

      void MainWindow::keyPressEvent(QKeyEvent *event) //included in .h file under the private category
      {
          if (event->KeyPress) {
              qDebug() << "key";
          }
      }
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Sucharek said in See if a key was presssed:

      I have this, but it only picks up...
      if (event->KeyPress) {

      Who knows, since I don't see any such QKeyEvent member variable?

      not just in the app, but globally.

      Is this possible?

      I hope not! You want to monitor the keyboard no matter which application has focus? Isn't that how keystroke stealers work? :) Maybe it's possible, but I would have thought it would be down to the windowing system having some native way of doing it? Like Windows has e.g. How to use System-Wide Hotkeys in your Qt application, but that's for like some special key combination registered with the OS, not what you are asking for.

      S 1 Reply Last reply
      3
      • JonBJ JonB

        @Sucharek said in See if a key was presssed:

        I have this, but it only picks up...
        if (event->KeyPress) {

        Who knows, since I don't see any such QKeyEvent member variable?

        not just in the app, but globally.

        Is this possible?

        I hope not! You want to monitor the keyboard no matter which application has focus? Isn't that how keystroke stealers work? :) Maybe it's possible, but I would have thought it would be down to the windowing system having some native way of doing it? Like Windows has e.g. How to use System-Wide Hotkeys in your Qt application, but that's for like some special key combination registered with the OS, not what you are asking for.

        S Offline
        S Offline
        Sucharek
        wrote on last edited by
        #3

        Hi @JonB, never thought about the keystore thing :o
        I'm making a screen on time program and I'm counting active and passive time. For the passive time, I need to detect mouse movement and the keyboard. I guess I'll need to stick with the mouse.
        Thanks for the help.

        JonBJ 1 Reply Last reply
        0
        • S Sucharek

          Hi @JonB, never thought about the keystore thing :o
          I'm making a screen on time program and I'm counting active and passive time. For the passive time, I need to detect mouse movement and the keyboard. I guess I'll need to stick with the mouse.
          Thanks for the help.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @Sucharek said in See if a key was presssed:

          a screen on time program

          I'm afraid I don't know what that is?

          active and passive time

          Active & passive time in your app, or overall usage of PC by user?

          Anything to do with another program, or even a different window in your own app, is not going to be MainWindow:: anything.

          S 1 Reply Last reply
          0
          • JonBJ JonB

            @Sucharek said in See if a key was presssed:

            a screen on time program

            I'm afraid I don't know what that is?

            active and passive time

            Active & passive time in your app, or overall usage of PC by user?

            Anything to do with another program, or even a different window in your own app, is not going to be MainWindow:: anything.

            S Offline
            S Offline
            Sucharek
            wrote on last edited by
            #5

            Well, when the app is running, it counts the time, so I guess in the app.

            JonBJ 1 Reply Last reply
            0
            • S Sucharek

              Well, when the app is running, it counts the time, so I guess in the app.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @Sucharek
              I'm getting confused. I think you need to be very specific about what key presses you are looking for, or have to look for:

              • Those to one window in your app?
              • Those to any window in your app?
              • Those to completely separate windows belonging to other applications?
              S 1 Reply Last reply
              0
              • JonBJ JonB

                @Sucharek
                I'm getting confused. I think you need to be very specific about what key presses you are looking for, or have to look for:

                • Those to one window in your app?
                • Those to any window in your app?
                • Those to completely separate windows belonging to other applications?
                S Offline
                S Offline
                Sucharek
                wrote on last edited by
                #7

                The ones that are completely separate windows belonging to other applications, so the 3rd option you listed.

                JonBJ 1 Reply Last reply
                0
                • S Sucharek

                  The ones that are completely separate windows belonging to other applications, so the 3rd option you listed.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #8

                  @Sucharek
                  Then like I said I do not think Qt offers anything for that, and I do not know if the Windows OS/windowing system even allows it from a normal program (e.g. not the device driver, and excluding specialist software like "keyloggers").

                  1 Reply Last reply
                  0
                  • hskoglundH Online
                    hskoglundH Online
                    hskoglund
                    wrote on last edited by hskoglund
                    #9

                    Hi, for listening to keystrokes regardless of which program or window they end up in, there are a couple of Win32 API:s you can use from a normal (unprivileged) program, for example: SetWindowsHookExW()

                    JonBJ 1 Reply Last reply
                    3
                    • hskoglundH hskoglund

                      Hi, for listening to keystrokes regardless of which program or window they end up in, there are a couple of Win32 API:s you can use from a normal (unprivileged) program, for example: SetWindowsHookExW()

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #10

                      @hskoglund said in See if a key was presssed:

                      you can use from a normal (unprivileged) program, for example: SetWindowsHookExW()

                      Wow! So without any warning or elevated privilege, any Windows program I install could be logging all keystrokes I make in any application? Nice.

                      1 Reply Last reply
                      0
                      • hskoglundH Online
                        hskoglundH Online
                        hskoglund
                        wrote on last edited by
                        #11

                        Yes, it's been around since Windows 3.0, there's an older forum discussion here
                        I posted an example program there, see if I can get the link to gitlab working again...

                        JonBJ 1 Reply Last reply
                        3
                        • hskoglundH hskoglund

                          Yes, it's been around since Windows 3.0, there's an older forum discussion here
                          I posted an example program there, see if I can get the link to gitlab working again...

                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by
                          #12

                          @hskoglund
                          Indeed! There is a blow-by-blow discussion in https://0x00sec.org/t/windows-keylogging-part-i/99

                          Scary how easy Windows makes it!

                          1 Reply Last reply
                          0
                          • hskoglundH Online
                            hskoglundH Online
                            hskoglund
                            wrote on last edited by
                            #13

                            As I remember it, those API:s were initially designed for training/teaching how to use a computer (not for spying on you!) for example the acronym CBT you'll see in the docs stands for Computer Base Training :-)

                            J.HilkJ 1 Reply Last reply
                            3
                            • hskoglundH hskoglund

                              As I remember it, those API:s were initially designed for training/teaching how to use a computer (not for spying on you!) for example the acronym CBT you'll see in the docs stands for Computer Base Training :-)

                              J.HilkJ Offline
                              J.HilkJ Offline
                              J.Hilk
                              Moderators
                              wrote on last edited by
                              #14

                              @hskoglund the root to hell is paved with good intentions....

                              but this is also the reason, why anti-cheat software from games has to be so terrible invasive on the Operating System.


                              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                              Q: What's that?
                              A: It's blue light.
                              Q: What does it do?
                              A: It turns blue.

                              1 Reply Last reply
                              0
                              • S Offline
                                S Offline
                                Sucharek
                                wrote on last edited by Sucharek
                                #15

                                Hi all, thanks for your replies, but I think I'm gonna have to stick with only the mouse movement. If I get this right, it won't work on Linux, so that's a bad thing.
                                Edit: Messing with Windows APIs is something I have no idea how to do and it would take days for me to learn it. The mouse is probably the only way.
                                Thanks again for your answers.

                                JonBJ 1 Reply Last reply
                                0
                                • S Sucharek

                                  Hi all, thanks for your replies, but I think I'm gonna have to stick with only the mouse movement. If I get this right, it won't work on Linux, so that's a bad thing.
                                  Edit: Messing with Windows APIs is something I have no idea how to do and it would take days for me to learn it. The mouse is probably the only way.
                                  Thanks again for your answers.

                                  JonBJ Offline
                                  JonBJ Offline
                                  JonB
                                  wrote on last edited by
                                  #16

                                  @Sucharek
                                  I never knew why you needed to track key presses to other applications. And I hope Linux doesn't allow it anyway! :)

                                  I don't know whether it helps, but you can (I believe) track focus changes/activate/deactivate windows in your app. Which I think would accompany going typing keys into another application. Maybe you could investigate those?

                                  S 1 Reply Last reply
                                  1
                                  • JonBJ JonB

                                    @Sucharek
                                    I never knew why you needed to track key presses to other applications. And I hope Linux doesn't allow it anyway! :)

                                    I don't know whether it helps, but you can (I believe) track focus changes/activate/deactivate windows in your app. Which I think would accompany going typing keys into another application. Maybe you could investigate those?

                                    S Offline
                                    S Offline
                                    Sucharek
                                    wrote on last edited by
                                    #17

                                    Ok, I maybe I'll take a look at that. Thanks.

                                    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