4

I found a lot of examples how to get key modifiers like this one. But I don't get it working for checking if they are pressed and hold at the same time.

This should be rather easy, as CTRL+SHIFT are standard key combinations.

From the above linked example:

modifiers = QtGui.QApplication.keyboardModifiers()
if modifiers == QtCore.Qt.ShiftModifier:
    print('Shift+Click')
elif modifiers == QtCore.Qt.ControlModifier:
    print('Control+Click')
else:
    print('Click')

We see that either CTRL or SHIFT are tested for. But I need a check which finds if both are pressed at the same time.

I tested lots of variants like this one:

if modifiers == (QtCore.Qt.ControlModifier and QtCore.Qt.ShiftModifier):

I found something written in C but I don't seem to be able to translate it.

Community
  • 1
  • 1
chiefenne
  • 565
  • 2
  • 15
  • 30

1 Answers1

5

My Python is rusty but try if (modifiers & QtCore.Qt.ControlModifier) and (modifiers & QtCore.Qt.ShiftModifier):

This checks if both Control and Shift bitfields are set in modifiers.

David Ching
  • 1,903
  • 17
  • 21