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. Global keypress handler
Forum Updated to NodeBB v4.3 + New Features

Global keypress handler

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 2 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.
  • M Offline
    M Offline
    Mehodin
    wrote on last edited by
    #1

    Hey,

    I've been looking for a while but i cant seem to find a global keypress handler in qt5, is there anyone that has already done this? I struggled with this for about 5 hours already and I can't seem to figure it out, thanks in advance.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      What about
      http://doc.qt.io/qt-5/qshortcut.html#details
      Alternatively there is
      http://doc.qt.io/qt-5/qcoreapplication.html#notify

      But can I ask what is the use case ?

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mehodin
        wrote on last edited by
        #3

        The UI will be spawned in another process, and show() / hide() will be called on the keypress depending on whether it's currently visible, i tried some stuff (GetKeyState, RegisterHotKey) but keystate is a blocking call and would prevent the UI from working properly, and i couldnt figure out registerhotkey.

        I also tired QShortCut already, it requires the UI to be in focus, ill take a look at notify but im affraid that it's also going to require focus.

        mrjjM 1 Reply Last reply
        1
        • M Mehodin

          The UI will be spawned in another process, and show() / hide() will be called on the keypress depending on whether it's currently visible, i tried some stuff (GetKeyState, RegisterHotKey) but keystate is a blocking call and would prevent the UI from working properly, and i couldnt figure out registerhotkey.

          I also tired QShortCut already, it requires the UI to be in focus, ill take a look at notify but im affraid that it's also going to require focus.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          @Mehodin
          So its a global OS key handler you are after ?
          Like RegisterHotKey ?

          http://amin-ahmadi.com/2015/11/14/how-to-use-system-wide-hotkeys-in-your-qt-application/

          1 Reply Last reply
          1
          • M Offline
            M Offline
            Mehodin
            wrote on last edited by
            #5

            something like that, i just couldnt figure out registerhotkey, if you could help me with that that would be great though.

            (Also could you like one of my posts? So i dont have to wait 10 minutes between every reply?)

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

              Hi
              The small sample i liked, worked fine, last time i tried it. ( for other forum poster)
              Its only for windows, but i assume thats fine ?

              1 Reply Last reply
              0
              • M Offline
                M Offline
                Mehodin
                wrote on last edited by
                #7

                yeah, it's for windows only, which sample do you mean?

                mrjjM 1 Reply Last reply
                0
                • M Mehodin

                  yeah, it's for windows only, which sample do you mean?

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by mrjj
                  #8

                  @Mehodin
                  The link i gave, but i found the test project from other post :)
                  https://www.dropbox.com/s/yh7ynoy9k3kzu3l/globalkey.zip?dl=0

                  it just show message box, but you can make it do what ever you want and
                  app dont need to have focus.

                  1 Reply Last reply
                  1

                  • Login

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