How to do key press and key release in script please?

@wojtryb @EyeOdin

I’m still having a bit of a problem if someone please would know a way around it please.

I have:

def createActions(self, window):
    SHORTCUTS = [
      Qt.Key_Control,
      Qt.Key_Shift,
      Qt.Key_Alt,
      Qt.Key_X
    ]

    self.c_canvas_rotation = window.createAction("c_canvas_rotation", "Custom Canvas Rotation", "tools/scripts")
    self.c_canvas_rotation.setAutoRepeat(True)
    self.qwin = window.qwindow()
    self.winFilter = self.windowFilter(SHORTCUTS,
    [False] * len(SHORTCUTS),
    False)
    self.qwin.installEventFilter(self.winFilter)

Which install the EventFilter to a qwindow.

Which works ok, then I go to the EventFilter:

  class windowFilter(QWindow):
    def __init__(self, shortcuts, shortcuts_registered, shortcut_bool, parent=None):
      super().__init__(parent)
      self.SHORTCUTS = shortcuts
      self.SHORTCUTS_REGISTERED = shortcuts_registered
      self.SHORTCUT_BOOL = shortcut_bool

    def eventFilter(self, obj, event):
      # KEY PRESS
      if event.type() == QEvent.KeyPress:
        # Register key presses equal to SHORTCUTS
        for i in range(len(self.SHORTCUTS)):
          if event.key() == self.SHORTCUTS[i]:
            self.SHORTCUTS_REGISTERED[i] = True
        dialog = Dialog(self.SHORTCUTS_REGISTERED) # Dialog is just a way for me to print nothing else and works jsut fine

The problem is that KeyPress doesn’t work. Or to be precise it does kind of work if I use ALT key (this I assume works in windows as usual which means to give focus to menu and not the rest of the app) and then I can press alt, shift or ctrl and it works but it doesn’t work for other keys or most of them (if they are assigned to do something in krita it’s not working).

So 2 problems. It seems krita is catching keypresses on qwindow I guess and it doesn’t propagate to my code unless I change focus (which is not a working solution).

  1. Is there a way to get the keypresses here please?
  2. Is there a way to get kepyresses from keys that are already assigned (for example in my case I use ctrl, alt, shift, X as a combination just to see what I can use and X doesn’t work even out of focus (through alt)

Later I have a KeyRelease part but that one seems to be working just fine so I omitted it in this post.

The plugin itself is supposed to just do regular canvas rotation nothing more, I’m working on this: