PDA

View Full Version : Want to detect keyboard key press other than modifier keys



Rajesh.Rathod
25th October 2013, 06:43
Hi All,
I have Qt application in which I want to handle combination of "SHIFT + B" & button press on QPushButton. (Shortcut is combination of "SHIFT + B + button press)
I am able to identify ctrl key press using QApplication::keyboardModifiers() in button press handler, but I am not able to find a way to detect whether "B" is currently pressed or not, if anyone have some idea, please help.

I don't want to use keypress & keyrelease to track the keyboard key.

Thanks.

stampede
25th October 2013, 06:53
I don't want to use keypress & keyrelease to track the keyboard key.
Can you explain why not ?

Rajesh.Rathod
25th October 2013, 07:07
Hi,
The reason I don't want to use keypress & keyrelease is, I was searching something similar to queryKeyboardModifiers which is I think supported in Qt 5.1, otherwise as a last option I will use keypress & keyrelease event.
One more option I was thinking is if it's not possible in Qt then I will use platform specific API for detecting this key.
for your information, I am using Qt 4.7.3.

Thanks,

stampede
25th October 2013, 07:19
So, you will give away platform portability and/or compatibility between Qt versions just to solve such simple task in platform-specific way ? Anyway, its your decision, but I'd go for keypress / keyrelease, it will work in Qt4/Qt5 and all platforms.
For windows, you can use GetKeyState (http://msdn.microsoft.com/en-us/library/windows/desktop/ms646301(v=vs.85).aspx) function. I don't know about mac or unix.