jtroo / kanata

Improve keyboard comfort and usability with advanced customization
GNU Lesser General Public License v3.0
3.08k stars 129 forks source link

Bug: Defoverrides combined with one-shot shift gives both shifted and non-shifted key. #1210

Closed hgersen closed 2 months ago

hgersen commented 3 months ago

Requirements

Describe the bug

When combining one-shot modifiers with the defoverrides functionality to break up common key-pairs I get both the shifted and non-shifted key on the keys that I override in the config when using the tap of the one-shot functionality. This does not happen with keys that are not overridden or when holding the modifier when tapping the overridden key.

A minimal config to display the problem is below. Note that doing the override using a key such as = would have the same effect.

Relevant kanata config

(defcfg
  process-unmapped-keys yes
)

(defsrc
  l  '  lsft
)

(defoverrides
  ;; using keypad to avoid overwriting symbols
  (kp0) (')
  (lsft kp0) (grv)
)

(defalias
  osf (one-shot 1000 lsft)
)

(deflayer base
  l  kp0 @osf
)

To Reproduce

  1. Load the config; tap the left shift key followed by '
  2. This will display a back-tick followed by ' instead of the expected back-tick
  3. Confirm that oneshot works correctly by typing the letter L, which should display a single capital L

Expected behavior

When using oneshot modifier such as the shift in combination with an overridden key only the shifted symbol should be displayed, which in this case would be the backtick

Kanata version

1.6.1

Debug logs

No response

Operating system

Linux [Chimera Linux]

Additional context

No response

rpnfan commented 2 months ago

Did you test the 1.7 pre-release? When I remember correct that is fixed there. I also had problems with 1.6.1, but with the pre-release it is fine.

hgersen commented 2 months ago

Did you test the 1.7 pre-release? When I remember correct that is fixed there. I also had problems with 1.6.1, but with the pre-release it is fine.

I have now tested with the 1.7 pre-release version. This bug is also in the pre-release, so it hasn't been fixed.

jtroo commented 2 months ago

What do logs show when running with the --debug flag?

hgersen commented 2 months ago

What do logs show when running with the --debug flag?

The debug output is below for the following sequence: 1) first press is oneshot shift + ' 2) second is shift held + '

17:19:49.1420 [INFO] kanata v1.7.0-prerelease-1 starting
17:19:49.1422 [INFO] process unmapped keys: true
17:19:49.1424 [INFO] NOTE: kanata was compiled to never allow cmd
17:19:49.1424 [DEBUG] (1) kanata_parser::cfg::alloc: freeing allocations of length 0
17:19:49.1426 [DEBUG] (1) kanata_parser::cfg: All overrides:
[
    Override {
        in_non_mod_osc: KEY_KP0,
        out_non_mod_osc: KEY_APOSTROPHE,
        in_mod_oscs: [],
        out_mod_oscs: [],
    },
    Override {
        in_non_mod_osc: KEY_KP0,
        out_non_mod_osc: KEY_GRAVE,
        in_mod_oscs: [
            KEY_LEFTSHIFT,
        ],
        out_mod_oscs: [],
    },
]
17:19:49.1426 [INFO] config file is valid
17:19:49.1432 [INFO] Created device "/dev/input/event17"
17:19:49.1432 [INFO] Sleeping for 2s. Please release all keys and don't press additional ones. Run kanata with --help to see how understand more and how to disable this sleep.
17:19:51.1436 [INFO] entering the processing loop
17:19:51.1438 [INFO] entering the event loop
17:19:51.1439 [INFO] looking for devices in /dev/input
17:19:51.1440 [DEBUG] (1) kanata_state_machine::oskbd::linux: Detected Keyboard: name=AT Translated Set 2 keyboard physical_path=Some("isa0060/serio0/input0")
17:19:51.1440 [INFO] Init: catching only releases and sending immediately
17:19:51.1535 [DEBUG] (1) kanata_state_machine::oskbd::linux: Detected Mouse: name=ELAN0678:00 04F3:3195 Mouse physical_path=Some("i2c-ELAN0678:00")
17:19:51.1715 [DEBUG] (1) kanata_state_machine::oskbd::linux: Detected Mouse: name=TPPS/2 Elan TrackPoint physical_path=Some("isa0060/serio1/input0")
17:19:51.3866 [INFO] registering /dev/input/event0: "AT Translated Set 2 keyboard"
17:19:51.4036 [INFO] registering /dev/input/event2: "ELAN0678:00 04F3:3195 Mouse"
17:19:51.4235 [INFO] registering /dev/input/event4: "TPPS/2 Elan TrackPoint"
17:19:51.6738 [INFO] Starting kanata proper
17:19:51.6738 [INFO] You may forcefully exit kanata by pressing lctl+spc+esc at any time. These keys refer to defsrc input, meaning BEFORE kanata remaps keys.
17:19:58.5504 [DEBUG] (3) kanata_state_machine::kanata: process recv ev KeyEvent { code: KEY_LEFTSHIFT (42), value: Press }
17:19:58.5507 [DEBUG] (3) kanata_state_machine::kanata: key press     LShift
17:19:58.5507 [DEBUG] (3) kanata_state_machine::oskbd::linux: send to uinput: InputEvent { time: SystemTime { tv_sec: 0, tv_nsec: 0 }, kind: Key(KEY_LEFTSHIFT), value: 1 }
17:19:58.6295 [DEBUG] (3) kanata_state_machine::kanata: process recv ev KeyEvent { code: KEY_LEFTSHIFT (42), value: Release }
17:19:59.1281 [DEBUG] (3) kanata_state_machine::kanata: process recv ev KeyEvent { code: KEY_APOSTROPHE (40), value: Press }
17:19:59.1282 [DEBUG] (3) kanata_parser::cfg::key_override: using override Override { in_non_mod_osc: KEY_KP0, out_non_mod_osc: KEY_GRAVE, in_mod_oscs: [KEY_LEFTSHIFT], out_mod_oscs: [] }
17:19:59.1282 [DEBUG] (3) kanata_state_machine::kanata: key release   LShift
17:19:59.1282 [DEBUG] (3) kanata_state_machine::oskbd::linux: send to uinput: InputEvent { time: SystemTime { tv_sec: 0, tv_nsec: 0 }, kind: Key(KEY_LEFTSHIFT), value: 0 }
17:19:59.1282 [DEBUG] (3) kanata_state_machine::kanata: key press     Grave
17:19:59.1282 [DEBUG] (3) kanata_state_machine::oskbd::linux: send to uinput: InputEvent { time: SystemTime { tv_sec: 0, tv_nsec: 0 }, kind: Key(KEY_GRAVE), value: 1 }
17:19:59.1282 [DEBUG] (3) kanata_parser::cfg::key_override: using override Override { in_non_mod_osc: KEY_KP0, out_non_mod_osc: KEY_GRAVE, in_mod_oscs: [KEY_LEFTSHIFT], out_mod_oscs: [] }
17:19:59.1293 [DEBUG] (3) kanata_parser::cfg::key_override: using override Override { in_non_mod_osc: KEY_KP0, out_non_mod_osc: KEY_GRAVE, in_mod_oscs: [KEY_LEFTSHIFT], out_mod_oscs: [] }
`17:19:59.1305 [DEBUG] (3) kanata_parser::cfg::key_override: using override Override { in_non_mod_osc: KEY_KP0, out_non_mod_osc: KEY_GRAVE, in_mod_oscs: [KEY_LEFTSHIFT], out_mod_oscs: [] }
17:19:59.1316 [DEBUG] (3) kanata_parser::cfg::key_override: using override Override { in_non_mod_osc: KEY_KP0, out_non_mod_osc: KEY_GRAVE, in_mod_oscs: [KEY_LEFTSHIFT], out_mod_oscs: [] }
17:19:59.1328 [DEBUG] (3) kanata_parser::cfg::key_override: using override Override { in_non_mod_osc: KEY_KP0, out_non_mod_osc: KEY_APOSTROPHE, in_mod_oscs: [], out_mod_oscs: [] }
17:19:59.1328 [DEBUG] (3) kanata_state_machine::kanata: key release   Grave
17:19:59.1328 [DEBUG] (3) kanata_state_machine::oskbd::linux: send to uinput: InputEvent { time: SystemTime { tv_sec: 0, tv_nsec: 0 }, kind: Key(KEY_GRAVE), value: 0 }
17:19:59.1328 [DEBUG] (3) kanata_state_machine::kanata: key press     Quote
17:19:59.1329 [DEBUG] (3) kanata_state_machine::oskbd::linux: send to uinput: InputEvent { time: SystemTime { tv_sec: 0, tv_nsec: 0 }, kind: Key(KEY_APOSTROPHE), value: 1 }
'17:19:59.1799 [DEBUG] (3) kanata_state_machine::kanata: process recv ev KeyEvent { code: KEY_APOSTROPHE (40), value: Release }
17:19:59.1800 [DEBUG] (3) kanata_state_machine::kanata: key release   Quote
17:19:59.1800 [DEBUG] (3) kanata_state_machine::oskbd::linux: send to uinput: InputEvent { time: SystemTime { tv_sec: 0, tv_nsec: 0 }, kind: Key(KEY_APOSTROPHE), value: 0 }
17:20:02.7628 [DEBUG] (3) kanata_state_machine::kanata: process recv ev KeyEvent { code: KEY_LEFTSHIFT (42), value: Press }
17:20:02.7629 [DEBUG] (3) kanata_state_machine::kanata: key press     LShift
17:20:02.7629 [DEBUG] (3) kanata_state_machine::oskbd::linux: send to uinput: InputEvent { time: SystemTime { tv_sec: 0, tv_nsec: 0 }, kind: Key(KEY_LEFTSHIFT), value: 1 }
17:20:03.0121 [DEBUG] (3) kanata_state_machine::kanata: process recv ev KeyEvent { code: KEY_LEFTSHIFT (42), value: Repeat }
17:20:03.0121 [DEBUG] (3) kanata_state_machine::kanata::key_repeat: key outs for active layer-while-held: [KEY_LEFTSHIFT];
17:20:03.0121 [DEBUG] (3) kanata_state_machine::kanata::key_repeat: repeat    LShift
17:20:03.0122 [DEBUG] (3) kanata_state_machine::oskbd::linux: send to uinput: InputEvent { time: SystemTime { tv_sec: 0, tv_nsec: 0 }, kind: Key(KEY_LEFTSHIFT), value: 2 }
17:20:03.0354 [DEBUG] (3) kanata_state_machine::kanata: process recv ev KeyEvent { code: KEY_APOSTROPHE (40), value: Press }
17:20:03.0354 [DEBUG] (3) kanata_parser::cfg::key_override: using override Override { in_non_mod_osc: KEY_KP0, out_non_mod_osc: KEY_GRAVE, in_mod_oscs: [KEY_LEFTSHIFT], out_mod_oscs: [] }
17:20:03.0355 [DEBUG] (3) kanata_state_machine::kanata: key release   LShift
17:20:03.0355 [DEBUG] (3) kanata_state_machine::oskbd::linux: send to uinput: InputEvent { time: SystemTime { tv_sec: 0, tv_nsec: 0 }, kind: Key(KEY_LEFTSHIFT), value: 0 }
17:20:03.0355 [DEBUG] (3) kanata_state_machine::kanata: key press     Grave
17:20:03.0355 [DEBUG] (3) kanata_state_machine::oskbd::linux: send to uinput: InputEvent { time: SystemTime { tv_sec: 0, tv_nsec: 0 }, kind: Key(KEY_GRAVE), value: 1 }
`17:20:03.0366 [DEBUG] (3) kanata_parser::cfg::key_override: using override Override { in_non_mod_osc: KEY_KP0, out_non_mod_osc: KEY_GRAVE, in_mod_oscs: [KEY_LEFTSHIFT], out_mod_oscs: [] }
17:20:03.0377 [DEBUG] (3) kanata_parser::cfg::key_override: using override Override { in_non_mod_osc: KEY_KP0, out_non_mod_osc: KEY_GRAVE, in_mod_oscs: [KEY_LEFTSHIFT], out_mod_oscs: [] }
17:20:03.0387 [DEBUG] (3) kanata_parser::cfg::key_override: using override Override { in_non_mod_osc: KEY_KP0, out_non_mod_osc: KEY_GRAVE, in_mod_oscs: [KEY_LEFTSHIFT], out_mod_oscs: [] }
17:20:03.0398 [DEBUG] (3) kanata_parser::cfg::key_override: using override Override { in_non_mod_osc: KEY_KP0, out_non_mod_osc: KEY_GRAVE, in_mod_oscs: [KEY_LEFTSHIFT], out_mod_oscs: [] }
17:20:03.0409 [DEBUG] (3) kanata_parser::cfg::key_override: using override Override { in_non_mod_osc: KEY_KP0, out_non_mod_osc: KEY_GRAVE, in_mod_oscs: [KEY_LEFTSHIFT], out_mod_oscs: [] }
17:20:03.1506 [DEBUG] (3) kanata_state_machine::kanata: process recv ev KeyEvent { code: KEY_APOSTROPHE (40), value: Release }
17:20:03.1507 [DEBUG] (3) kanata_state_machine::kanata: key release   Grave
17:20:03.1507 [DEBUG] (3) kanata_state_machine::oskbd::linux: send to uinput: InputEvent { time: SystemTime { tv_sec: 0, tv_nsec: 0 }, kind: Key(KEY_GRAVE), value: 0 }
17:20:03.1508 [DEBUG] (3) kanata_state_machine::kanata: key press     LShift
17:20:03.1508 [DEBUG] (3) kanata_state_machine::oskbd::linux: send to uinput: InputEvent { time: SystemTime { tv_sec: 0, tv_nsec: 0 }, kind: Key(KEY_LEFTSHIFT), value: 1 }
17:20:03.3767 [DEBUG] (3) kanata_state_machine::kanata: process recv ev KeyEvent { code: KEY_LEFTSHIFT (42), value: Release }
17:20:03.3768 [DEBUG] (3) kanata_state_machine::kanata: key release   LShift
17:20:03.3768 [DEBUG] (3) kanata_state_machine::oskbd::linux: send to uinput: InputEvent { time: SystemTime { tv_sec: 0, tv_nsec: 0 }, kind: Key(KEY_LEFTSHIFT), value: 0 }
17:20:19.5170 [DEBUG] (3) kanata_state_machine::kanata: process recv ev KeyEvent { code: KEY_LEFTCTRL (29), value: Press }
17:20:19.5171 [DEBUG] (3) kanata_state_machine::kanata: key press     LCtrl
17:20:19.5172 [DEBUG] (3) kanata_state_machine::oskbd::linux: send to uinput: InputEvent { time: SystemTime { tv_sec: 0, tv_nsec: 0 }, kind: Key(KEY_LEFTCTRL), value: 1 }
17:20:19.7507 [DEBUG] (3) kanata_state_machine::kanata: process recv ev KeyEvent { code: KEY_C (46), value: Press }
17:20:19.7508 [DEBUG] (3) kanata_state_machine::kanata: key press     C
17:20:19.7508 [DEBUG] (3) kanata_state_machine::oskbd::linux: send to uinput: InputEvent { time: SystemTime { tv_sec: 0, tv_nsec: 0 }, kind: Key(KEY_C), value: 1 }
jtroo commented 2 months ago

Can you try this: https://github.com/jtroo/kanata/blob/main/docs/config.adoc#override-release-on-activation

hgersen commented 2 months ago

Adding override-release-on-activation yes to defcfg indeed fixes this behavior (both in the test as well as in my normal config).

Thanks for the hint as that wasn't an obvious one!

rpnfan commented 2 months ago

Adding override-release-on-activation yes to defcfg [...]

I had that in my config, therefore 1.71 was working for me. I guess we will not be the last ones stumbling over that problem. Any ideas how to either solve that in code or make it easier (documentation update)?

jtroo commented 2 months ago

@hgersen if you still remember the places you thought to look to see if this was fixable, that would be helpful to know.

Some straightforward places to add some docs would be the one-shot and overrides docs I suppose!