Does anyone know how to check and return what key was pressed (preferably in Qt C++ or Python)? This is a Qt GUI app with a QTextEdit box. I can check if a key was pressed, but I need to mimic on screen exactly what keyboard keys were pressed when typing incl. small/caps keys.
I’m sorry I really don’t understand this question. If the standard input output procedures for your language don’t work don’t work, you can try a language’s derivatives of the POSIX read/write routines (“man 2 read” “man 2 write” and maybe say “man 2 poll” from the command line might help) If you are in some sort of a QT event structure that is throwing you a keypress event I really don’t know because I’ve never used QT, but posting the event you’re getting and need to get the key for would probably help someone who know about that sort of thing.
You need to be able to access the raw XEvent that was translated to a string by the X library. This contains the information about which key was depressed or released (they are distinct events). This raw event structure is the information before keyboard mappings ans such are taken into account. Programming details depend on the X toolkit you use.
For information, you could use the xev program in a terminal. This program is available in the xorg-x11 package in opensuse 11.1 . It displays what is sent by X when a key is pressed or released.
What I meant was I can catch a keyPressedEvent and check what key was pressed, but in order to find out exactly what letter/key was pressed I have to check it against every single key on a keyboard. In Python I use a dictionary and it works fine. What I was wondering if there’s a simpler way to know, for example, if you get a Qt.Key_X then it would return “X”, rather than getting the Qt.Key_X code and then getting it’s ascii representation which I manually put in the dictionary for all keyboard keys.
have you already tried to use QKeyEvent::text (). Maybe this is what you are searching for. I guess the python Qt API also provides this functionality.