Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
One a question...
ahura_24 last edited by
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
lycis last edited by
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.
rschaub last edited by
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...