Checking for letters pressed when mouse is pressed
-
wrote on 1 Jun 2017, 12:19 last edited by
Hi everyone !
I'm developing an application using Qt in C++.
When there is a mouse click, I would like to check if there are letters pressed on the keyboard. So far, I found solutions when the keys pressed are specific ones like Shift, Control .. but not when a letter is pressed.
Do you have any advice for me ?
PS: Sorry if this topic isn't in the right category, I wasn't sure where to post it.
Thank you !
Sandra
-
wrote on 1 Jun 2017, 12:34 last edited by
Combine
virtual void mousePressEvent(QMouseEvent * event)
and
virtual void keyPressEvent(QKeyEvent * event)
-
wrote on 1 Jun 2017, 12:36 last edited by
-
wrote on 1 Jun 2017, 12:56 last edited by
Indeed, my application is a QSlicerApplication (I'm developing a module in 3DSlicer) and I'm not sure I can use exactly the same solutions as if I were only working with Qt.
I tried this :
when leftButtonPressEvent :
Qt::KeyboardModifiers modifier = qSlicerApplication::application()->keyboardModifiers(); if (QApplication::keyboardModifiers().testFlag(Qt::ShiftModifier) == true) { std::cout << "shift pressed" << std::endl; }
This works very well ... but it only works for specific keys (Control, Shift ..), is there something like that but working for letters pressed ?
-
wrote on 1 Jun 2017, 13:08 last edited by Eddy 6 Jan 2017, 13:08
-
Hi and welcome to devnet,
Can you explain why do you need to know whether a letter is currently pressed ?
A long press on such a key usually triggers the auto-repeat of the system so it might make things a bit more difficult.
5/6