-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: kanata breaks SDL2-based games #567
Comments
Update: it works properly on Debian 12 using XFCE4. |
I suspect there's nothing that can be done about this, at least from the Kanata side, with the LLHOOK mechanism. The SDL2 library probably detects the synthetic inputs and decides to handle them differently than real inputs. The only workaround would likely be use interception (* see warnings). Unless of course someone with more SDL2 knowledge can correct me, maybe there are other knobs to turn. |
I'm not super familiar with SDL2's inner workings, but I'll see what I can find out. I'm surprised nobody has run into this so far -- SDL is a pretty popular framework for building games and game engines on. |
I naively reviewed SDL2's source, and it reads separate Windows events for keydown, keyup, and text input. Where in kanata's source does it generate the event for Windows? |
kanata/src/oskbd/windows/mod.rs Line 62 in b585a5e
|
@tpstevens did you solve this problem? I've been using kanata for 3 months and this has been an issue for me. Usually, I just close kanata which is far from ideal. Interception is also not an option for me, because some games ban it (from what I've researched, many bots use it). @jtroo I do not know much about LLHOOK or SDL2, but, in my case, the inputs from kanata were recognized, it's just action keys (if I may call that) like enter or space, for example, did not work as intended. I even tested writing some text inside the applications and all keys were normal, including space. I did not test w, a, s, d keys, but I can test it, if it's relevant. |
One could try playing around with adding the Unicode or Scancode flags: https://learn.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-keybdinput And then compile and test. |
I've started with your suggestion about unicode, however encountered a problem from the start, which sounds basic, but couldn't find anywhere in code, docs or discussions: how to insert a unicode from the hex value? Is it even possible? I've tested the common ways for utf-8 and utf-16, but no success. For example, to space character: \u0020, \u0020, u0020, \u{0020}, "\u0020". All of them gave the error "unicode expects exactly one unicode character as an argument" |
Based on your comment, my understanding is you're trying the Unicode action in the Kanata config? My comment was more playing with the code using these flags:
At this code: kanata/src/oskbd/windows/mod.rs Line 62 in b585a5e
|
I was trying exactly that.
Ok, I'll give a look into this, thanks |
@jtroo your hint was on point. Problem solved.
To get the values of each key, look into this site: Virtual key codes
|
Thanks for doing the investigation work. It's probably worth investigating at some point in the future if using |
Will that properly handle holding a key down for a long time and then releasing?
…On Tue, Oct 17, 2023 at 3:46 PM, jtroo ***@***.***(mailto:On Tue, Oct 17, 2023 at 3:46 PM, jtroo <<a href=)> wrote:
Thanks for doing the investigation work.
It's probably worth investigating at some point in the future if using KEYEVENTF_SCANCODE for all (or most, if not possible for all) keys would be better than what kanata is doing now.
—
Reply to this email directly, [view it on GitHub](#567 (comment)), or [unsubscribe](https://github.com/notifications/unsubscribe-auth/ADA56O7EA5CVC2OHSO45RKTX74DDZAVCNFSM6AAAAAA5FHNENCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONRXGMYTCMJUHE).
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Not sure what the context is around that, I'm not aware of any issue around holding a key for a long time. |
The original issue that I discovered was that kanata wasn't sending keydown and keyup events (at least how SDL2 receives them). But I think I misread the sample code above -- it looks like the SendInput function is sent for the up and down event, while I originally thought it was only for keys up. So I'd expect all keys to work properly if |
Edit: windows key was bugged, so I had to come wih an if for it. Also changed code Btw, I've been testing the new method for all keys for the past 3 days and didn't notice any change at all besides everything also working on the app I wanted (keys like enter, space and all modifiers works normal now).
|
I have added the |
Hey, @jtroo. Just saw your comment, not that active on git. 😓 Here are the comments I left to my future self so I could remember what I was doing: For example, left arrow and 4 from numpad. For the scancode, they have the same low byte, What I imagine is that SDL2-based apps use the scancode, not sure why they use the wrong one though (I even read some problems very similar to ours with people programming games, because the inputs were being translated wrong). With my last code posted, I converted the virtualcode to scancode, but passed only the low byte to 'kb_input.wScan' and the program assumed 0x00 as the high byte for all the keys, resulting in all the extended keys with the wrong output. I've made an array with the virtualcodes to be able to identify the extended keys and change the high byte. The array was made from looking into font 1 to know whick keys were extended and got the virtualcode inside font 2. If there is any question, don't mind asking. Here is the new code:
|
Thanks for the updated code! |
Not work in Terraria, any key in layer can not accept by game. I can only close Katana to solve it. So sad... |
How about keep a black name list, in which kanata not active in those program to solve it? |
Which variant of kanata did you try? Please try one of: winiov2 or scancode from the release page, if you have not tried it. |
I tried the winiov2 edition, it works well, thanks for you work! |
how to compile the winiov2 version myself? same question for the scancode version, maybe |
You can find the commands used to build them in the justfile. |
Requirements
Describe the bug
On Windows 10, kanata sends events that get treated by SDL (and probably the OS?) as text input events but not keyup and keydown events.
Without kanata running:
With kanata running:
I've tested with my own games built with SDL2 (which is how I generated the above logs) and other games that use SDL2. I'm happy to test on Debian as well.
Relevant kanata config
No response
To Reproduce
Expected behavior
kanata should send keydown and keyup events. I'd expect that the keydown might come with a little delay after kanata has decided what the key should resolve to.
Kanata version
1.4.0
Debug logs
No response
Operating system
Windows 10
Additional context
No response
The text was updated successfully, but these errors were encountered: