jtroo / kanata

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

Bug: special buttons on function row not working on macos #1141

Closed pizdoponi closed 4 months ago

pizdoponi commented 4 months ago

Requirements

Describe the bug

When kanata is not running, the keys on the uppermost row (function keys row) work as expected. When I press screen brightness down, screen brightness decreases, when I press mute button, the audio is muted, etc.

I tried to obtain the same behavior with kanata, to no avail. In defsrc I put the relevant icons on their respective keys, but they act as function keys. Thus when I press πŸ”Š, instead of volume increasing, f12 is registered.

I further tried to put πŸ”Š key on "keyboard proper", where the ] character is otherwise located. Pressing that key, the volume increases. Therefore it seems something must be wrong with the uppermost row, where the keys are registered as function keys when they should not be.

There is an option to have the function keys act as actual function keys on macos, but I have that turned off all the time (picture below).

Screenshot 2567-07-14 at 17 52 32

The keyboard input source I am using is: ABC - Extended

Relevant kanata config

(defcfg
  process-unmapped-keys no
)

;; TODO: get the upper row with special keys working
(defsrc
    esc  πŸ”…   πŸ”†   nop0 nop1 nop2 nop3 β—€β—€   ▢⏸   β–Άβ–Ά   πŸ”‡   πŸ”‰   πŸ”Š
    lsgt 1    2    3    4    5    6    7    8    9    0    -    =    bspc
    tab  q    w    e    r    t    y    u    i    o    p    [    ]
    caps a    s    d    f    g    h    j    k    l    ;    '    \    ret
    lsft grv  z    x    c    v    b    n    m    ,    .    /    rsft
    fn   lctl lalt lmet           spc            rmet ralt
)

(defvar
  ;; Note: consider using different time values for your different fingers.
  ;; For example, your pinkies might be slower to release keys and index fingers faster.
  tap-time 200
  hold-time 150
)

(defalias ;; modifiers
    spc (tap-hold 200 200 spc (layer-while-held num_nav)) ;; spc
    bspc (tap-hold 200 200 bspc (layer-while-held sym)) ;; rmet
    cr (tap-hold 200 200 ret (layer-while-held fun)) ;; ralt
    tab (tap-hold 200 200 tab (layer-while-held sym)) ;; lmet
    esc (tap-hold 200 200 esc (layer-while-held fun)) ;; lalt
)

(defalias ;; home row mods
    a (tap-hold $tap-time $hold-time a lalt)
    r (tap-hold $tap-time $hold-time r lctl)
    s (tap-hold $tap-time $hold-time s lsft)
    ;; t (tap-hold $tap-time $hold-time t lmet)
    ;; n (tap-hold $tap-time $hold-time n rmet)
    t (chord tnesc t)
    n (chord tnesc n)
    e (tap-hold $tap-time $hold-time e rsft)
    i (tap-hold $tap-time $hold-time i rctl)
    o (tap-hold $tap-time $hold-time o ralt)
)

(defchords tnesc 100
    (t  ) (tap-hold $tap-time $hold-time t lmet)
    (  n) (tap-hold $tap-time $hold-time n rmet)
    (t n) esc
)

(defalias ;; symbols
    < (tap-hold $tap-time $hold-time S-, lalt)
    ! (tap-hold $tap-time $hold-time S-1 lctl)
    min (tap-hold $tap-time $hold-time - lsft)
    = (tap-hold $tap-time $hold-time = lmet)
    obrc (tap-hold $tap-time $hold-time S-9 rmet)
    cbrc (tap-hold $tap-time $hold-time S-0 rsft)
    ? (tap-hold $tap-time $hold-time S-/ rctl)
    scol (tap-hold $tap-time $hold-time ; ralt)

    > S-.
    ^ S-6
    # S-3
    * S-8
    $ S-4
    & S-7
    ~ S-grv
    | S-\
    % S-5
    at S-2
)

(defalias ;; numbers, navigation
    four (tap-hold $tap-time $hold-time 4 rmet)
    five (tap-hold $tap-time $hold-time 5 rsft)
    six (tap-hold $tap-time $hold-time 6 rctl)
    left (tap-hold $tap-time $hold-time left lctl)
    down (tap-hold $tap-time $hold-time down lsft)
    rght (tap-hold $tap-time $hold-time right lmet)
)

(deflayer colemakdh
    esc   πŸ”…    πŸ”†    nop0  nop1  nop2  nop3  β—€β—€    ▢⏸    β–Άβ–Ά    πŸ”‡    πŸ”‰    πŸ”Š
    grv   1     2     3     4     5     6     7     8     9     0     -     =     bspc
    tab   q     w     f     p     b     j     l     u     y     '     πŸ”†    πŸ”Š
    caps  @a    @r    @s    @t    g     m     @n    @e    @i    @o    C-v   \     ret
    lsft  z     x     c     d     v     βœ—     k     h     ,     .     /     rsft
    fn    lctl  @esc  @tab              @spc              @bspc @cr
)

(deflayer sym
    βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—
    βœ—     M-1   M-2   M-3   M-4   M-5   M-6   M-7   M-8   M-9   M-0   βœ—     βœ—     βœ—
    M-tab @^    @#    @*    @$    βœ—     ,     [     ]     \     '     βœ—     βœ—
    βœ—     @<    @!    @min  @=    @>    `     @obrc @cbrc @?    @scol βœ—     βœ—     βœ—
    βœ—     @at   @%    +     @|    @&    XX    @~    S-[   S-]   .     /     βœ—
    βœ—     βœ—     /     S--               S-;               S-'   βœ—
)

(deflayer num_nav
    βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—
    βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—
    βœ—     βœ—     βœ—     up    βœ—     βœ—     βœ—     7     8     9     βœ—     βœ—     βœ—
    βœ—     lalt  @left @down @rght βœ—     βœ—     @four @five @six  ralt  βœ—     βœ—     βœ—
    βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     1     2     3     βœ—     βœ—
    βœ—     βœ—     βœ—     ret               βœ—                 0     βœ—
)

(deflayer fun
    βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—
    βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—
    βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—     βœ—
    βœ—     f1    f2    f3    f4    f5    f6    f7    f8    f9    f10   βœ—     βœ—     βœ—
    βœ—     f11   f12   f13   f14   f15   f16   f17   f18   f19   f20   βœ—     βœ—
    βœ—     βœ—     βœ—     βœ—                 βœ—                 βœ—     βœ—
)

To Reproduce

  1. In system settings > keyboard > text input > input sources select ABC - Extended as input source
  2. Turn use function keys in system settings off
  3. Run kanata with config above

Expected behavior

The screen brightness up/down, media prev/pause/next, volume mute/down/up keys on the function row keys do what they should instead of being registered as function keys.

Kanata version

kanata 1.6.0

Debug logs

❯ sudo ./kanata_macos_arm64 --debug --cfg main.kbd
2024-07-14T17:47:50.045543+02:00 [INFO] kanata v1.6.0 starting
2024-07-14T17:47:50.045952+02:00 [INFO] process unmapped keys: false
2024-07-14T17:47:50.046036+02:00 [INFO] NOTE: kanata was compiled to never allow cmd
2024-07-14T17:47:50.046046+02:00 [DEBUG] (1) kanata_parser::cfg::alloc: freeing allocations of length 0
2024-07-14T17:47:50.046604+02:00 [INFO] config file is valid
2024-07-14T17:47:50.046616+02:00 [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.
2024-07-14T17:47:52.051729+02:00 [INFO] entering the processing loop
2024-07-14T17:47:52.051904+02:00 [INFO] entering the event loop
2024-07-14T17:47:52.052024+02:00 [INFO] Init: catching only releases and sending immediately
connected
driver_activated 1
driver_connected 0
driver_version_mismatched 0
2024-07-14T17:47:52.687144+02:00 [INFO] Starting kanata proper
2024-07-14T17:47:52.687238+02:00 [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.
driver_connected 1
2024-07-14T17:47:59.22133+02:00 [DEBUG] (1) kanata_state_machine::kanata::macos: InputEvent { value: 48, page: 7, code: 4294967295 } is unrecognized!
2024-07-14T17:47:59.221442+02:00 [DEBUG] (1) kanata_state_machine::oskbd::macos: Attempting to write InputEvent { value: 48, page: 7, code: 4294967295 } DKEvent { value: 48, page: 7, code: 4294967295 }
2024-07-14T17:47:59.22147+02:00 [DEBUG] (1) kanata_state_machine::kanata::macos: InputEvent { value: 0, page: 7, code: 1 } is unrecognized!
2024-07-14T17:47:59.221684+02: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-07-14T17:47:59.221762+02:00 [DEBUG] (1) kanata_state_machine::kanata::macos: sending KeyEvent { code: KEY_RIGHTBRACE, value: Press } to processing loop
2024-07-14T17:47:59.22206+02:00 [DEBUG] (1) kanata_state_machine::kanata::macos: InputEvent { value: 48, page: 7, code: 4294967295 } is unrecognized!
2024-07-14T17:47:59.222086+02:00 [DEBUG] (1) kanata_state_machine::oskbd::macos: Attempting to write InputEvent { value: 48, page: 7, code: 4294967295 } DKEvent { value: 48, page: 7, code: 4294967295 }
2024-07-14T17:47:59.222119+02:00 [DEBUG] (2) kanata_state_machine::kanata: process recv ev KeyEvent { code: KEY_RIGHTBRACE, value: Press }
2024-07-14T17:47:59.22217+02:00 [DEBUG] (2) kanata_state_machine::kanata: key press     VolUp
2024-07-14T17:47:59.222206+02:00 [DEBUG] (2) kanata_state_machine::oskbd::macos: Attempting to write InputEvent { value: 1, page: 12, code: 233 } DKEvent { value: 1, page: 12, code: 233 }
2024-07-14T17:47:59.271939+02:00 [DEBUG] (1) kanata_state_machine::kanata::macos: InputEvent { value: 0, page: 7, code: 4294967295 } is unrecognized!
2024-07-14T17:47:59.271967+02: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-07-14T17:47:59.27198+02:00 [DEBUG] (1) kanata_state_machine::kanata::macos: InputEvent { value: 0, page: 7, code: 1 } is unrecognized!
2024-07-14T17:47:59.271983+02: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-07-14T17:47:59.271989+02:00 [DEBUG] (1) kanata_state_machine::kanata::macos: sending KeyEvent { code: KEY_RIGHTBRACE, value: Release } to processing loop
2024-07-14T17:47:59.272+02:00 [DEBUG] (1) kanata_state_machine::kanata::macos: InputEvent { value: 0, page: 7, code: 4294967295 } is unrecognized!
2024-07-14T17:47:59.272005+02:00 [DEBUG] (2) kanata_state_machine::kanata: process recv ev KeyEvent { code: KEY_RIGHTBRACE, value: Release }
2024-07-14T17:47:59.272016+02:00 [DEBUG] (2) kanata_state_machine::kanata: key release   VolUp
2024-07-14T17:47:59.272022+02:00 [DEBUG] (2) kanata_state_machine::oskbd::macos: Attempting to write InputEvent { value: 0, page: 12, code: 233 } DKEvent { value: 0, page: 12, code: 233 }
2024-07-14T17:47:59.272052+02: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-07-14T17:48:00.922694+02:00 [DEBUG] (1) kanata_state_machine::kanata::macos: InputEvent { value: 69, page: 7, code: 4294967295 } is unrecognized!
2024-07-14T17:48:00.922768+02: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-07-14T17:48:00.92279+02:00 [DEBUG] (1) kanata_state_machine::kanata::macos: InputEvent { value: 0, page: 7, code: 1 } is unrecognized!
2024-07-14T17:48:00.9228+02: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-07-14T17:48:00.922846+02:00 [DEBUG] (1) kanata_state_machine::kanata::macos: KeyEvent { code: KEY_F12, value: Press } is not mapped
2024-07-14T17:48:00.922864+02:00 [DEBUG] (1) kanata_state_machine::oskbd::macos: Attempting to write InputEvent { value: 1, page: 7, code: 69 } DKEvent { value: 1, page: 7, code: 69 }
2024-07-14T17:48:00.922877+02:00 [DEBUG] (1) kanata_state_machine::kanata::macos: InputEvent { value: 69, page: 7, code: 4294967295 } is unrecognized!
2024-07-14T17:48:00.922886+02: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 }
^[[24~2024-07-14T17:48:00.998969+02:00 [DEBUG] (1) kanata_state_machine::kanata::macos: InputEvent { value: 0, page: 7, code: 4294967295 } is unrecognized!
2024-07-14T17:48:00.999005+02: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-07-14T17:48:00.999026+02:00 [DEBUG] (1) kanata_state_machine::kanata::macos: InputEvent { value: 0, page: 7, code: 1 } is unrecognized!
2024-07-14T17:48:00.999034+02: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-07-14T17:48:00.999041+02:00 [DEBUG] (1) kanata_state_machine::kanata::macos: KeyEvent { code: KEY_F12, value: Release } is not mapped
2024-07-14T17:48:00.999047+02:00 [DEBUG] (1) kanata_state_machine::oskbd::macos: Attempting to write InputEvent { value: 0, page: 7, code: 69 } DKEvent { value: 0, page: 7, code: 69 }
2024-07-14T17:48:00.999053+02:00 [DEBUG] (1) kanata_state_machine::kanata::macos: InputEvent { value: 0, page: 7, code: 4294967295 } is unrecognized!
2024-07-14T17:48:00.999057+02: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 Sonoma 14.3

Additional context

Just wanted to drop a quick thank you for amazing work

jtroo commented 4 months ago

This looks like potentially a dupe of https://github.com/jtroo/kanata/issues/975 but your observation that some special keys behave correctly is interesting πŸ€”

pizdoponi commented 4 months ago

The issues are very similar, my bad for missing it. I managed to solve the problem following this guide from #975.

A quick note for anyone having the same problem. The following resolved the issue for me:

  1. in defsrc put the actual fn keys on the f-row.
  2. in your main (or any other layer) simply put the special keys wherever you want.

A very simple config to illustrate the point:

(defsrc
    esc  f1   f2   f3   f4   f5   f6   f7   f8   f9   f10  f11  f12
    lsgt 1    2    3    4    5    6    7    8    9    0    -    =    bspc
    tab  q    w    e    r    t    y    u    i    o    p    [    ]
    caps a    s    d    f    g    h    j    k    l    ;    '    \    ret
    lsft grv  z    x    c    v    b    n    m    ,    .    /    rsft
    fn   lctl lalt lmet           spc            rmet ralt
)

(deflayer base
    ;; everything is exactly the same, only the f-row is changed.
    ;; you can of course change any of the other mappings.
    esc  πŸ”…   πŸ”†    βœ—    βœ—    βœ—    βœ—    β—€β—€   ▢⏸   β–Άβ–Ά   πŸ”‡   πŸ”‰   πŸ”Š
    lsgt 1    2    3    4    5    6    7    8    9    0    -    =    bspc
    tab  q    w    e    r    t    y    u    i    o    p    [    ]
    caps a    s    d    f    g    h    j    k    l    ;    '    \    ret
    lsft grv  z    x    c    v    b    n    m    ,    .    /    rsft
    fn   lctl lalt lmet           spc            rmet ralt
)

Maybe the f-row keys are registered as fn keys and the operating system does something to make them into brightness/audio/do not disturb etc. keys, but underneath they are still fn keys, and thus where not being processed correctly in the config, because it tries to reference a key that isn't there?

Anyhow, I managed to resolve the issue, so I'm closing this.