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. One a question...
Forum Updated to NodeBB v4.3 + New Features

One a question...

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 2.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.
  • A Offline
    A Offline
    ahura_24
    wrote on last edited by
    #1

    hi everybody. i want to write one trainer game. i need a function in Qt library that works like GetAsyncKeyState in api.
    get all keyboard input key.
    tnx for help

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lycis
      wrote on last edited by
      #2

      There is no function that is directly corresponding to that Windows API function. The question is what you want to achieve with it. "QWidget":http://qt-project.org/doc/qt-4.8/qwidget.html gives you the possiblity to react on key presses or releases with the according functions "QWidget::keyPressEvent(...) ":http://qt-project.org/doc/qt-4.8/qwidget.html#keyPressEvent and "QWidget::keyReleaseEvent(...)":http://qt-project.org/doc/qt-4.8/qwidget.html#keyReleaseEvent.

      If you want to remember the status of a key for asynchronous use you could set a flag in keyPressEvent(...) and delete it in keyReleaseEvent(...). But a word of warning: This flag will get corrupted if the user changes the window with the key still pressed and when it is released outside of your application. So there needs to be some coding done on that part.

      If you want to create shortcuts there are other supported methods for that.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rschaub
        wrote on last edited by
        #3

        you might also want to have a look at "eventFilters":http://qt-project.org/doc/qt-4.8/qobject.html#eventFilter
        I recently wrote a keygrabber that logs all keyboard input while my application has focus. If your app doesn't have focus (if it's in the background), you'll have a hard time getting keyboard input - depending on the OS you're developing for, it might even be impossible...

        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