How does Krita Detect Shortcut Key? Related to Shortcut Failure Bug

In OS = Windows 11 and Krita 5.2.2(lastest version),

I wonder if Krita detect a shortcut key by a fully match method, aka, if F10 is not included in any shortcut key, a F10 + Ctrl + Shift + A will not trigger anything in Krita. By the way, the similar key stroke F10 + Ctrl + D will trigger deselection on PhotoShop.

It seems not a problem at all, but here’s my concern.


Shortcut Failure “Bug” From 2 years ago

An shortcut problem had been raised by some users two years ago in this forum (Abnormal canvas rotation and shortcut keys failure), which in most cases was caused by WeChat. For some reason, WeChat will press a virtual key F22 while started and not release that key at all.

Simple Test C++ Program

I wrote a simple C++ program to simulate what WeChat do at the opening:

#include <windows.h>

INPUT onlyPress[] = {
    INPUT {
        .type = INPUT_KEYBOARD,
        .ki = {
            .wVk = VK_F22,
        }
    }
};

INPUT pressAndRelease[] = {
    *onlyPress,
    INPUT {
        .type = INPUT_KEYBOARD,
        .ki = {
            .wVk = VK_F22,
            .dwFlags = KEYEVENTF_KEYUP,
        }
    }
};

int main(int argc, char* argv[]) {
    SendInput(1, onlyPress, sizeof onlyPress);
//    SendInput(2, pressAndRelease, sizeof pressAndRelease);
    return 0;
}

If WeChat pressAndRelease that key, Krita works normal, but WeChat didn’t. It onlyPress that key and never gets it released. You could run this program and for me it 100% causes Krita 5.2.2 to lose signal from Ctrl, Alt, Shift and Space, meaning a lot of shortcuts won’t work anymore. Only a restart of Krita (or an lock-then-unlock of Windows) will fix this, very annoying.

I use a software quicker to detect the keyboard state, aka which key has been pressed, including virtual keys, and release that virtual key after test.

Along side holding virtual key, a constant hold of a physical key that doesn’t bind to anything like F10, will also make Krita’s shortcut fail, just like I mentioned at the top of this post.

More Issues from the Shortcut Recognization Method of Krita

In fact, WeChat is just a common case. I found a recent report on a software pressed HanjaMode virtual key and not releasing it, causing Krita’s shortcut to fail, well, again. (This report in Chinese Baidu Forum, on 2024/1/25)

So, there are always some softwares that don’t follow a normal way, and hold a key for a long time.

My Hope

I know that it’s impossible for me to change Wechat’s source code. Even if I managed to do that, other irregular software does exists that will cause the same problem. But Krita is open sourced, so I have my hope here to not lost this loving drawing software because of some kind of bug.

I hope we could add some protections on this problem(just like PhotoShop and many other still-fine softwares that won’t be affected by bad softwares like WeChat).

If the question “if Krita detect a shortcut key by a fully match method” has its answer to be “yes”, then we can change it to a partially match method, which will solve the problem in my guess.

Partially Shortcut Match Method

I mean, when additional key is pressed, such as a manually pressed F10, or an auto pressed F22, we ignore that key since it doesn’t exists in shortcut key table. So that F10 + Ctrl + Shift + A can also trigger deselection in Krita, because we ignore F10.

There might be other solutions better than this according to Krita’s software architecture. I will assume the problem code is in something related to key stroke parsing.

Currently I’m trying to go through Krita’s source code to locate the problem code.


What’s your opinion on this topic? Please let me know!

2 Likes

Krita input event is based on Qt.
So there’s chance that it’s on Qt side the thing has to be reviewed.
You can try to implement a small Qt application to check if it’s impacted or not (you can also try Qt5 and Qt6 to check if Qt6 manage this differently)

But if a key in not released by another software, can be hard to determinate if it’s a keyboard thing or a software thing.

If I understand, the trick consist to interperet combination Key1+Key2 as Key1 if combination Key1+Key2 doesn’exist?

  1. What to do if combination Key1+Key2 really exist?
  2. I’m not sure on my side to want undefined keyboard combination trigger something else… (also, i’m pretty sure that some people will come here to start to complain that, doing a key combination that is not defined in Krita triggers action…)

I don’t know Qt’s system enough, but may be it would be better when Krita got focus again to “reset” keyboard status or something like that (if possible).

Grum999

1 Like

Thanks for this information, and I’ll try to learn Qt to figure out what’s happening.

Here’re my opinion on your questions:


Then we should perform that shortcut combination.


I think that probably isn’t the case, because the defineded part of the keystroke(such as Ctrl + Shift + A in combination F10 + Ctrl + Shift + A) is matched. If somehow Ctrl + Shift + A is pressed, although with some other keys, I think the user still means to deselect. The partially match isn’t equal to randomly remap.

If you means that F10 exists in other user defineded combinations, and my current “ignore” algorithm will not ignore it, you are right. I still need a more consise and logical describtion of “partially match”. Maybe I do need some Qt Demos to explain this. Thank you for reminding me that.

Additionally, the point is, there are other softwares that still servive in a virtual key interference(like PhotoShop I mentioned). I think this is a problem related to Robustness, meaning software should still work well in abnormal conditioins.

I’m pretty sure that Krita’s shortcuts use Qt Actions, so it’s not handling key press events itself.