jtroo / kanata

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

Bug: F-row key get override on MacOS #975

Open OnFireByte opened 5 months ago

OnFireByte commented 5 months ago

Requirements

Describe the bug

In my macbook, F-row get override to normal f1-f12 instead of normal feature (light control, sound control) when kanata is used.

This also happen when I try to turn on the "swap f-row to feature" setting (Image below), fn key + F-row key will still result in normal f1-f12

image

Relevant kanata config

No response

To Reproduce

  1. Running kanata
  2. waiting for driver_activated 1
  3. Done

Expected behavior

It shouldn't override anything.

Kanata version

kanata 1.6.0 (arm64, cmd allowed)

Debug logs

Happen when I press F12 (increase volume)

2024-04-24T19:32:48.957173+07:00 [DEBUG] (1) kanata_state_machine::kanata::macos: InputEvent { value: 69, page: 7, code: 4294967295 } is unrecognized!
2024-04-24T19:32:48.957267+07:00 [DEBUG] (1) kanata_state_machine::oskbd::macos: Attempting to write InputEvent { value: 69, page: 7, code: 4294967295 } DKEvent { value: 69, page: 7, code: 4294967295 }
2024-04-24T19:32:48.957286+07:00 [DEBUG] (1) kanata_state_machine::kanata::macos: InputEvent { value: 0, page: 7, code: 1 } is unrecognized!
2024-04-24T19:32:48.957298+07:00 [DEBUG] (1) kanata_state_machine::oskbd::macos: Attempting to write InputEvent { value: 0, page: 7, code: 1 } DKEvent { value: 0, page: 7, code: 1 }
2024-04-24T19:32:48.957337+07:00 [DEBUG] (1) kanata_state_machine::kanata::macos: sending KeyEvent { code: KEY_F12, value: Press } to processing loop
2024-04-24T19:32:48.957368+07:00 [DEBUG] (1) kanata_state_machine::kanata::macos: InputEvent { value: 69, page: 7, code: 4294967295 } is unrecognized!
2024-04-24T19:32:48.957383+07:00 [DEBUG] (1) kanata_state_machine::oskbd::macos: Attempting to write InputEvent { value: 69, page: 7, code: 4294967295 } DKEvent { value: 69, page: 7, code: 4294967295 }
2024-04-24T19:32:48.95741+07:00 [DEBUG] (2) kanata_state_machine::kanata: process recv ev KeyEvent { code: KEY_F12, value: Press }
2024-04-24T19:32:48.957451+07:00 [DEBUG] (2) kanata_state_machine::kanata: key press     F12
2024-04-24T19:32:48.957466+07:00 [DEBUG] (2) kanata_state_machine::oskbd::macos: Attempting to write InputEvent { value: 1, page: 7, code: 69 } DKEvent { value: 1, page: 7, code: 69 }
^[[24~2024-04-24T19:32:49.049204+07:00 [DEBUG] (1) kanata_state_machine::kanata::macos: InputEvent { value: 0, page: 7, code: 4294967295 } is unrecognized!
2024-04-24T19:32:49.049335+07:00 [DEBUG] (1) kanata_state_machine::oskbd::macos: Attempting to write InputEvent { value: 0, page: 7, code: 4294967295 } DKEvent { value: 0, page: 7, code: 4294967295 }
2024-04-24T19:32:49.049375+07:00 [DEBUG] (1) kanata_state_machine::kanata::macos: InputEvent { value: 0, page: 7, code: 1 } is unrecognized!
2024-04-24T19:32:49.049383+07:00 [DEBUG] (1) kanata_state_machine::oskbd::macos: Attempting to write InputEvent { value: 0, page: 7, code: 1 } DKEvent { value: 0, page: 7, code: 1 }
2024-04-24T19:32:49.049396+07:00 [DEBUG] (1) kanata_state_machine::kanata::macos: sending KeyEvent { code: KEY_F12, value: Release } to processing loop
2024-04-24T19:32:49.049417+07:00 [DEBUG] (1) kanata_state_machine::kanata::macos: InputEvent { value: 0, page: 7, code: 4294967295 } is unrecognized!
2024-04-24T19:32:49.050545+07:00 [DEBUG] (2) kanata_state_machine::kanata: process recv ev KeyEvent { code: KEY_F12, value: Release }
2024-04-24T19:32:49.050601+07:00 [DEBUG] (2) kanata_state_machine::kanata: key release   F12
2024-04-24T19:32:49.050611+07:00 [DEBUG] (2) kanata_state_machine::oskbd::macos: Attempting to write InputEvent { value: 0, page: 7, code: 69 } DKEvent { value: 0, page: 7, code: 69 }
2024-04-24T19:32:49.053527+07:00 [DEBUG] (1) kanata_state_machine::oskbd::macos: Attempting to write InputEvent { value: 0, page: 7, code: 4294967295 } DKEvent { value: 0, page: 7, code: 4294967295 }

Operating system

MacOS (arm64)

Additional context

No response

jtroo commented 5 months ago

Hi @OnFireByte,

To help a future reader, what is the minimal configuration that reproduces the behaviour?

jtroo commented 5 months ago

Also, does karabiner elements reproduce the same or does karabiner work as intended?

OnFireByte commented 5 months ago

Hi @OnFireByte,

To help a future reader, what is the minimal configuration that reproduces the behaviour?

  • Are you mapping f1-f12 in defsrc?
  • Are you using process-unmapped-keys yes?

Also, does karabiner elements reproduce the same or does karabiner work as intended?

  1. I didn't map anything to f1-f12, I only do the home row mod
  2. For process-unmapped-keys yes, I already try removing it, but the problem still occurred
  3. Karabiner work fine for me
yzhuang commented 5 months ago

I also ran into this issue, and it happens with or without process-unmapped-keys yes. It can be reproduced using simple configs like: https://github.com/jtroo/kanata/blob/main/cfg_samples/minimal.kbd

A related question is: what is the defsrc key code for the fn key? The below is what Karabiner EventViewer reports when the fn key is pressed.

[
  {
    "type": "down",
    "name": {"apple_vendor_top_case_key_code":"keyboard_fn"},
    "usagePage": "255 (0x00ff)",
    "usage": "3 (0x0003)",
    "misc": "flags fn"
  },
  {
    "type": "up",
    "name": {"apple_vendor_top_case_key_code":"keyboard_fn"},
    "usagePage": "255 (0x00ff)",
    "usage": "3 (0x0003)",
    "misc": ""
  },
]
jtroo commented 5 months ago

The fn key is fn.

https://github.com/jtroo/kanata/blob/b1e828b4cda220eda3bc4e0aef2f9afba5fc9b4f/parser/src/keys/mod.rs#L283

yzhuang commented 5 months ago

The fn key is fn.

https://github.com/jtroo/kanata/blob/b1e828b4cda220eda3bc4e0aef2f9afba5fc9b4f/parser/src/keys/mod.rs#L283

Thank you very much! Would be nice to update https://github.com/jtroo/kanata/blob/main/cfg_samples/all_keys_in_defsrc.kbd to include fn as well!

yzhuang commented 5 months ago

@jtroo Thanks for the pointer to the file https://github.com/jtroo/kanata/blob/b1e828b4cda220eda3bc4e0aef2f9afba5fc9b4f/parser/src/keys/mod.rs and it was super helpful for me to find many keycodes I needed.

I was able to resolve the issue by explicit handling the F-key row and the fn key. CC @OnFireByte

I.e.

;; add this row to your defsrc. Need to add the fn key as well.
(defsrc
  esc  f1   f2   f3   f4   f5   f6   f7   f8   f9   f10  f11  f12
  ...
  ...
  fn
)

;; then you can create a fn layer. E.g. mine is:
(deflayer fn
  _    brdn brup _    _    _    _    _    _    _    mute vold volu
  ...
)

;; then map your fn key to `fnl` as shown below.
(defalias
  fnl (layer-while-held fn)
)

The reason why I believe this is needed is because Karabiner also handles the F-keys explicitly. See attached screenshot: image

Update: In case you tap the fn key to switch layout like me, this is even better:

(defalias
  fnl (tap-hold 200 200 fn (layer-toggle fn))
)
yzhuang commented 5 months ago

It would still be nice to fix the bug--looks like the fn key code is not available on Windows, so having fn in defsrc breaks my configs compatibility in Windows.

39555 commented 4 months ago

A working minimal configuration

(defsrc
       f1    f2   f3   f4   f5  f6    f7   f8   f9   f10   f11   f12
  fn
)

(defalias
  fnl (tap-hold 200 200 fn (layer-toggle fn))
)

(deflayer base
       f1    f2   f3   f4   f5  f6    f7   f8   f9   f10   f11   f12
  @fnl
)

;; Some keys are missing: `Mission Control`, `Launchpad`, `dictation`, ` Do Not Disturb`
(deflayer fn
      brdn  brup  _    _    _    _   prev  pp  next  mute  vold  volu
  _
)

EDIT:

(defalias
  fnl (tap-hold 200 200 fn (layer-toggle fn))
)

for being able to also switch languages. Thanks @yzhuang !!

raynertanxw commented 1 month ago

Did anyone manage to find out the keycodes for Mission Control? I can live without spotlight (f4), dictation (f5), and do not disturb (f6) keys. But f3 (Mission Control) is something I would like to still retain.

roubaobaozi commented 2 weeks ago

Did anyone manage to find out the keycodes for Mission Control? I can live without spotlight (f4), dictation (f5), and do not disturb (f6) keys. But f3 (Mission Control) is something I would like to still retain.

Mission Control is by default ctrl+up arrow, so you could map it to that.

Check System Settings > Keyboard > Keyboard Shortcuts to see if it still is that, and you can find Do Not Disturb and Spotlight are, I didn’t see Dictation but it might be in there somewhere too.