View Full Version : Capture keyboard by hiden Widget and print text into text cursor

23rd September 2014, 03:21
Hi all,

I've developped an widget application in QT. For now, I'm compiling for windows and I intend to compile for linux in the future.

So, my widget always stays hiden and it has an icon menu for user configuring. What I need to do now is get a keyboard event, manipulate it and then print it into text cursor from windows. For example, if the cursor is on browser url, my programm should get keyboard events, manipulate and print some data into browser url.

If it was a console, it should get data from stdin and prints something into stdout.

I've implemented using Keyboard event. Something like http://www.qtcentre.org/threads/45159-keyPressEvent-not-being-called

The problem is: this only woks if the widget is active, not hiden.

I though in using this: http://qt-project.org/doc/qt-4.8/eventsandfilters.html

For sending data is the "same" problem, the widget is not active, so, how to put data to cursor text? Shall I use QTextCursor (http://qt-project.org/doc/qt-4.8/qtextcursor.html)? I've tried something, without success.

Shall I use a thread?

Does anybody can help with this issue?


25th September 2014, 01:59
Sounds like you are trying to program a keylogger. Qt key stroke events are not going to help. You need to find out how to intercept the keyboard input at OS level. There is probably a native windows interface for that. Perhaps you can configure an existing keylogger for your needs.

25th September 2014, 02:24
Shall I use a thread?

Does anybody can help with this issue?
I think "grabing" keyboard input is the only thing Qt can do for you, see: http://qt-project.org/doc/qt-5/qwidget.html#grabKeyboard
Hence Qt can't help you if you want to write a key logger. If you want to log keys, have a look at the source code of other key logger applications.