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. How to detect key press from outside of Qt program ?
Forum Updated to NodeBB v4.3 + New Features

How to detect key press from outside of Qt program ?

Scheduled Pinned Locked Moved General and Desktop
13 Posts 4 Posters 8.2k 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.
  • M Offline
    M Offline
    Md. Kayesh
    wrote on last edited by
    #1

    Hi,
    I want to make a project that will be able to detect any key pressed from outside of my project when my project is running. I hope it should be possible. Kindly help me.

    Thank you.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      stukdev
      wrote on last edited by
      #2

      A Keylogger?

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Md. Kayesh
        wrote on last edited by
        #3

        Yes something like that. But i actually don't need to know which key has been pressed, but i just need to get informed that a key has been pressed.

        1 Reply Last reply
        0
        • ? This user is from outside of this forum
          ? This user is from outside of this forum
          Guest
          wrote on last edited by
          #4

          You can use the system API libraries but your solution will not be portable and highly platform specific. I might be wrong but I think windows provides libraries with components that allow you to create handless to low level, system scale events. If you plan on doing it in windows you might want to dig around in "MSDN":http://msdn.microsoft.com

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Md. Kayesh
            wrote on last edited by
            #5

            Yes, I don't need to make it portable. But i am ignorant about the usage of Windows API. If i want to use that API in Qt what should i do? would you kindly suggest me something ?

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Asperamanca
              wrote on last edited by
              #6

              Here's your lead:

              http://msdn.microsoft.com/en-us/library/windows/desktop/ms645536(v=vs.85).aspx

              1 Reply Last reply
              0
              • A Offline
                A Offline
                Asperamanca
                wrote on last edited by
                #7

                ...but see also http://msdn.microsoft.com/en-us/library/windows/desktop/ms646302(v=vs.85).aspx

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  Md. Kayesh
                  wrote on last edited by
                  #8

                  hi Aseramanca,
                  How could i add the API while I am using Qt SDK 1.1.3 ?
                  Or, the necessary API is already added ?
                  What is the headerfile i have to add ?
                  Never mind I am a newbie in this sort of programming.

                  Thank you.

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    Asperamanca
                    wrote on last edited by
                    #9

                    The necessary header files are mentioned in the documentation of the specific functions. I have done most of my API work in other languages, so I can't give you a working solution for Qt SDK. But in general, you need the header files at compile time, and a DLL at run time. You might need to get a Windows SDK for the former, the latter should be on your system already.

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      giesbert
                      wrote on last edited by
                      #10

                      Hi,

                      if you are using MSVC tool chain, it is all there.
                      In mingw, I hope it is also, but I can't guarantee.

                      Windows API can just be used as any other API. Includ ethe needed headers, call the methods, add the needed libraries to the linker in qmake files.

                      What you need from the API is the system hooks stuff.

                      Nokia Certified Qt Specialist.
                      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        Asperamanca
                        wrote on last edited by
                        #11

                        bq. What you need from the API is the system hooks stuff.

                        Not in this use case. MS recommends using RawInput as replacement for Hooks in all use cases where this is possible.

                        Hooks increase the load on the kernel stacks, which can lead to strange and hard-to-track effects, if too many programs use them. Also, starting with Windows 7, hooks can be silently removed if they take too long to respond. Therefore, you cannot reliably use hooks to detect user input (well, it's one of those things that's probably going to work 98 % of the time, but still).

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          Md. Kayesh
                          wrote on last edited by
                          #12

                          I have seen some examples of hook somewhere, But I don't know about RawInput which seems to work better as your suggestion. Would you kindly post a snippet or a link so that i can learn about RawInput.

                          Thank you.

                          [quote author="Asperamanca" date="1331627603"]bq. What you need from the API is the system hooks stuff.

                          Not in this use case. MS recommends using RawInput as replacement for Hooks in all use cases where this is possible.

                          Hooks increase the load on the kernel stacks, which can lead to strange and hard-to-track effects, if too many programs use them. Also, starting with Windows 7, hooks can be silently removed if they take too long to respond. Therefore, you cannot reliably use hooks to detect user input (well, it's one of those things that's probably going to work 98 % of the time, but still).[/quote]

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            Asperamanca
                            wrote on last edited by
                            #13

                            MSDN is a good starting point:

                            http://msdn.microsoft.com/en-us/library/windows/desktop/ms645536(v=vs.85).aspx

                            In "using raw input", there are a few examples.

                            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