That’s possible
But, I don’t know if solution could be accepted…
The trick is to implement event filter.
Example made with a python plugin:
Save content to
~/.local/share/krita/pykrita/keycatcherdocker/__init__.py
from krita import *
from PyQt5.Qt import *
class KeyCatcherDocker(DockWidget):
"""Class to manage current selection"""
def __init__(self):
super(KeyCatcherDocker, self).__init__()
self.__installed=False
self.setWindowTitle("Key Catcher")
self.__lbl=QLabel('[Waiting to catch key]')
self.setWidget(self.__lbl)
def canvasChanged(self, canvas):
"""Notify when views are added or removed"""
if not self.__installed:
if Krita.instance().activeWindow():
# I'm very lazy too implement a better solution for this exemple
# for testing, just initialise catcher once a view has been created
w=Krita.instance().activeWindow().qwindow()
w.installEventFilter(self)
self.__installed=True
def eventFilter(self, source, event):
if isinstance(event, QKeyEvent):
if event.type()==QEvent.KeyRelease:
self.__lbl.setText("[Waiting to catch key]")
else:
modifiers=[]
if int(event.modifiers()) & Qt.ControlModifier == Qt.ControlModifier:
modifiers.append('CTRL')
if int(event.modifiers()) & Qt.ShiftModifier == Qt.ShiftModifier:
modifiers.append('SHIFT')
if int(event.modifiers()) & Qt.AltModifier == Qt.AltModifier:
modifiers.append('ALT')
if len(modifiers)>0:
self.__lbl.setText(f"Key({event.key()}) {' '.join(modifiers)}")
else:
self.__lbl.setText(f"Key({event.key()})")
print("Key event", event.key(), event.type())
return False
else:
return QObject.eventFilter(self, source, event)
testKeyCatcherDocker = DockWidgetFactory(f'Test_KeyCatcherDocker',
DockWidgetFactoryBase.DockRight,
KeyCatcherDocker)
Krita.instance().addDockWidgetFactory(testKeyCatcherDocker)
Save content to
~/.local/share/krita/pykrita/keycatcherdocker.desktop
[Desktop Entry]
Type=Service
ServiceTypes=Krita/PythonPlugin
X-KDE-Library=keycatcherdocker
X-Python-2-Compatible=false
X-Krita-Manual=Manual.html
Name=KeyCatcherDocker
Comment=testing key catching
Install plugin/restart Krita
Example of docker catching keys while I’m drawing:
- It catch key event but doesn’t stop/modify: shortcut and all other based key function will continue to work
- Catch keys even if docker don’t have focus
Notes: Plugin written in quick&dirty mode, sorry, especially for initialization part…
That’s my preferred solution
But I gave you tip if you really prefer the solution of CTRL key
Grum999