kanata icon indicating copy to clipboard operation
kanata copied to clipboard

Bug: other keys mapped to `lsft` causes undesired release of `lsft` key

Open Kuba314 opened this issue 5 months ago • 3 comments

Requirements

Describe the bug

I'm trying to have lctl on my physical lsft and have lsft on my physical caps. This works well, but I noticed that virtual lctl is not held after I Press lctl, Press lsft, Release lsft. This stops me from entering for example C-S-a followed by C-d without releasing the lctl key between the two shortcuts.

From the logs it seems like a kanata bug; kanata should know it's holding lctl, but it sends Release lctl before sending the user-entered shortcut letter (see the log).

This behaviour happens on lsft and caps physical keys (not on a and s) and the shortcut key has to be in defsrc otherwise the bug isn't there and everything works fine.

Relevant kanata config

(defsrc        lsft caps d    f)  ;; doesn't work for `C-d` and `C-f` shortcuts
;; (defsrc        a    s    d    f)  ;; seems to work for every `C-` shortcut

(deflayer test lctl lsft d    _)

To Reproduce

  1. Press physical lsft (mapped lctl)
  2. Press physical caps (mapped lsft)
  3. Release physical caps
  4. Press any letter
  5. Observe that the key is sent without the ctrl modifier

Expected behavior

lctl remains pressed.

Kanata version

1.6.0-prerelease-1

Debug logs

Output of physical Press lsft, Press caps, Release caps, Press f with the attached config. Note the key release LCtrl and key press F lines and their timing.

2024-03-02T23:15:52.8290383+01:00 [DEBUG] (1) kanata::kanata::windows::llhook: event loop: KeyEvent { code: KEY_LEFTSHIFT, value: Press }
2024-03-02T23:15:52.8304903+01:00 [DEBUG] (2) kanata::kanata: process recv ev KeyEvent { code: KEY_LEFTSHIFT, value: Press }
2024-03-02T23:15:52.8306918+01:00 [DEBUG] (2) kanata::kanata: key press     LCtrl
2024-03-02T23:15:53.0806922+01:00 [DEBUG] (1) kanata::kanata::windows::llhook: event loop: KeyEvent { code: KEY_LEFTSHIFT, value: Press }
2024-03-02T23:15:53.082114+01:00 [DEBUG] (2) kanata::kanata: process recv ev KeyEvent { code: KEY_LEFTSHIFT, value: Repeat }
2024-03-02T23:15:53.0822186+01:00 [DEBUG] (2) kanata::kanata: key outs for default layer: [KEY_LEFTCTRL];
2024-03-02T23:15:53.08227+01:00 [DEBUG] (2) kanata::kanata: repeat    LCtrl
2024-03-02T23:15:53.1119244+01:00 [DEBUG] (1) kanata::kanata::windows::llhook: event loop: KeyEvent { code: KEY_LEFTSHIFT, value: Press }
2024-03-02T23:15:53.1129266+01:00 [DEBUG] (2) kanata::kanata: process recv ev KeyEvent { code: KEY_LEFTSHIFT, value: Repeat }
2024-03-02T23:15:53.1129892+01:00 [DEBUG] (2) kanata::kanata: key outs for default layer: [KEY_LEFTCTRL];
2024-03-02T23:15:53.1130195+01:00 [DEBUG] (2) kanata::kanata: repeat    LCtrl
2024-03-02T23:15:53.1431321+01:00 [DEBUG] (1) kanata::kanata::windows::llhook: event loop: KeyEvent { code: KEY_LEFTSHIFT, value: Press }
2024-03-02T23:15:53.1443409+01:00 [DEBUG] (2) kanata::kanata: process recv ev KeyEvent { code: KEY_LEFTSHIFT, value: Repeat }
2024-03-02T23:15:53.1445161+01:00 [DEBUG] (2) kanata::kanata: key outs for default layer: [KEY_LEFTCTRL];
2024-03-02T23:15:53.1445405+01:00 [DEBUG] (2) kanata::kanata: repeat    LCtrl
2024-03-02T23:15:53.1472444+01:00 [DEBUG] (1) kanata::kanata::windows::llhook: event loop: KeyEvent { code: KEY_CAPSLOCK, value: Press }
2024-03-02T23:15:53.1477303+01:00 [DEBUG] (2) kanata::kanata: process recv ev KeyEvent { code: KEY_CAPSLOCK, value: Press }
2024-03-02T23:15:53.1477897+01:00 [DEBUG] (2) kanata::kanata: key press     LShift
2024-03-02T23:15:53.4040299+01:00 [DEBUG] (1) kanata::kanata::windows::llhook: event loop: KeyEvent { code: KEY_CAPSLOCK, value: Press }
2024-03-02T23:15:53.4049658+01:00 [DEBUG] (2) kanata::kanata: process recv ev KeyEvent { code: KEY_CAPSLOCK, value: Repeat }
2024-03-02T23:15:53.4050309+01:00 [DEBUG] (2) kanata::kanata: key outs for default layer: [KEY_LEFTSHIFT];
2024-03-02T23:15:53.4050487+01:00 [DEBUG] (2) kanata::kanata: repeat    LShift
2024-03-02T23:15:53.4160716+01:00 [DEBUG] (1) kanata::kanata::windows::llhook: event loop: KeyEvent { code: KEY_CAPSLOCK, value: Release }
2024-03-02T23:15:53.4163862+01:00 [DEBUG] (2) kanata::kanata: process recv ev KeyEvent { code: KEY_CAPSLOCK, value: Release }
2024-03-02T23:15:53.4164939+01:00 [DEBUG] (2) kanata::kanata: key release   LShift
2024-03-02T23:15:53.4169116+01:00 [DEBUG] (2) kanata::kanata::windows: lsft-arrowkey workaround: removing LShift at its typical coordinate
2024-03-02T23:15:53.4170039+01:00 [DEBUG] (2) kanata::kanata::windows: removing LShift from pressed keys
2024-03-02T23:15:53.6819452+01:00 [DEBUG] (1) kanata::kanata::windows::llhook: event loop: KeyEvent { code: KEY_F, value: Press }
2024-03-02T23:15:53.6834409+01:00 [DEBUG] (2) kanata::kanata: process recv ev KeyEvent { code: KEY_F, value: Press }
2024-03-02T23:15:53.6836278+01:00 [DEBUG] (2) kanata::kanata: key release   LCtrl
2024-03-02T23:15:53.6838594+01:00 [DEBUG] (2) kanata::kanata: key press     F
2024-03-02T23:15:53.7526101+01:00 [DEBUG] (1) kanata::kanata::windows::llhook: event loop: KeyEvent { code: KEY_F, value: Release }
2024-03-02T23:15:53.7541464+01:00 [DEBUG] (2) kanata::kanata: process recv ev KeyEvent { code: KEY_F, value: Release }
2024-03-02T23:15:53.7543725+01:00 [DEBUG] (2) kanata::kanata: key release   F
2024-03-02T23:15:54.0524055+01:00 [DEBUG] (1) kanata::kanata::windows::llhook: event loop: KeyEvent { code: KEY_LEFTSHIFT, value: Release }
2024-03-02T23:15:54.0542314+01:00 [DEBUG] (2) kanata::kanata: process recv ev KeyEvent { code: KEY_LEFTSHIFT, value: Release }

Operating system

Windows 11

Additional context

No response

Kuba314 avatar Mar 02 '24 22:03 Kuba314

Soo.... I don't know how exactly lsft-arrowkey workaround works, but removing LShift at its typical coordinate removes the lctl that I'm holding (probably because it's at lsft's typical coordinate.

Not sure why the lsft-arrowkey workaround has to guess like this and disregard any mapping that there can be to lsft (coord (0, 160)) but it's probably some ancient windows "feature". I do hope there's a fix for this...

Kuba314 avatar Mar 02 '24 23:03 Kuba314

Here's the original issue that sparked the creation of the workaround:

https://github.com/jtroo/kanata/issues/138

In summary, without the workaround, in some cases the lsft button state gets stuck because of Windows weirdness.

Perhaps there needs to be a way to turn the workaround off - I originally decided not to add one because I figured most people would keep their shift keys mapped as shift. When the workaround is off though, you will have the risk that your physical caps key, pressed alongside certain other buttons, will cause the physical lsft key state to be stuck as pressed. There is a tradeoff either way. The other alternative is Interception (which comes with its own issues).

jtroo avatar Mar 03 '24 00:03 jtroo

I wonder if this problem fixed by using winiov2.. Worth testing

jtroo avatar Apr 19 '24 18:04 jtroo