Skip to content

Keyd changes the default keycode for 'Fn' on my macbook #791

Open

Description

@celesrenata

Love your work!

I was hoping I could figure out a quick and dirty patch for my T2 Macbook.

I see that insrc/keys.h the FN key is mapped to 254, however, I need to map it to 464!

I tried changing the array to allow upto 465 to mimic your logic and changed the corresponding for loop in src/keys.c
unfortunately after recompiling it comes back as key 208!

I was wondering if you had any ideas on how I could patch this to work on my mac.

Thanks!
Celes

Activity

  1. rvaiya commented on Jul 26, 2024

    @rvaiya
    Owner

    I see that insrc/keys.h the FN key is mapped to 254, however, I need to map it to 464!

    That is keyd's internal code. It should be mapped to KEY_FN on input, which should be correctly defined by your kernel headers as 464.

    Have you tried running keyd monitor and inspecting the output? You should see something like fn down with a blank config.

    If not, can you post the output of sudo evtest1 while pressing the key? It is also possible that the hardware doesn't actually emit a distinct event for fn, which is a common problem on laptop keyboards.

    Footnotes

    1. Make sure keyd is disabled and that you select your physical board from the list. ↩

  2. szabba commented on Aug 10, 2024

    @szabba

    Not OP, but my situation on an M1 Macbook sounds similar. Not sure if I should open a separate issue for it.

    When I run sudo keyd monitor I get entries for most remapped keys. There's not output when I press leftcontrol (remmapped to layer(alt) in the main layer.

    What seems to be the relevant part of sudo evtest output (with keyd stopped) is:

    Event: time 1723288312.142961, -------------- SYN_REPORT ------------
    Event: time 1723288312.173686, type 4 (EV_MSC), code 4 (MSC_SCAN), value 700e0
    Event: time 1723288312.173686, type 1 (EV_KEY), code 29 (KEY_LEFTCTRL), value 0
    Event: time 1723288312.173686, -------------- SYN_REPORT ------------
    Event: time 1723288312.827211, type 4 (EV_MSC), code 4 (MSC_SCAN), value 700e0
    Event: time 1723288312.827211, type 1 (EV_KEY), code 29 (KEY_LEFTCTRL), value 1
    Event: time 1723288312.827211, -------------- SYN_REPORT ------------
    

    The config (cobbled together through trial and error)

    [ids]
    k:05ac:0281
    
    [global]
    default_layout = pl
    
    [main]
    delete = backspace
    
    rightmeta = layer(altgr)
    rightalt = rightcontrol
    
    leftcontrol = layer(fn)
    fn = leftcontrol
    leftmeta = alt
    leftalt = leftmeta
    
    home = C-left
    end = C-right
    pageup = C-up
    pagedown = C-down
    
    brightnessdown = f1
    brightnessup = f2
    scale = f3
    search = f4
    record = f5
    sleep = f6
    previoussong = f7
    playpause = f8
    nextsong = f9
    mute = f10
    volumedown = f11
    volumeup = f12
    
    [fn]
    left = home
    right = end
    up = pageup
    down = pagedown
    
    f1 = brightnessdown
    f2 = brightnessup
    f3 = scale
    f4 = search
    f5 = record
    f6 = sleep
    f7 = previoussong
    f8 = playpause
    f9 = nextsong
    f10 = mute
    f11 = volumedown
    f12 = volumeup
    
  3. themg95 commented on Oct 9, 2024

    @themg95

    Are there any updates on this? I can't access the second layer of my touchbar, which seems to be related to this issue.

  4. fathonix commented on Nov 30, 2024

    @fathonix

    I see that insrc/keys.h the FN key is mapped to 254, however, I need to map it to 464!

    That is keyd's internal code. It should be mapped to KEY_FN on input, which should be correctly defined by your kernel headers as 464.

    Have you tried running keyd monitor and inspecting the output? You should see something like fn down with a blank config.

    If not, can you post the output of sudo evtest1 while pressing the key? It is also possible that the hardware doesn't actually emit a distinct event for fn, which is a common problem on laptop keyboards.

    Footnotes

    1. Make sure keyd is disabled and that you select your physical board from the list. ↩

    M1 MacBook but having the same issue. keyd emitting 254 breaks tiny-dfr Touch Bar Fn layer functionality.

    keyd monitor detects Fn but evtest detects 254. Tested with blank config ([ids]\n*)

    $ sudo keyd monitor
    device added: 05ac:0341:c3080866 Apple Internal Keyboard / Trackpad (/dev/input/event0)
    device added: 0000:0000:1bf3eacc MacBookPro17,1 Touch Bar (/dev/input/event1)
    device added: 05ac:0341:3179765c Apple Internal Keyboard / Trackpad (/dev/input/event2)
    device added: 1209:316e:2b020ae1 Dynamic Function Row Virtual Input Device (/dev/input/event5)
    device added: 0fac:0ade:efba1ddf keyd virtual keyboard (/dev/input/event6)
    device added: 0fac:1ade:d2b36ae6 keyd virtual pointer (/dev/input/event7)
    keyd virtual keyboard	0fac:0ade:efba1ddf	enter up
    keyd virtual keyboard	0fac:0ade:efba1ddf	fn down
    keyd virtual keyboard	0fac:0ade:efba1ddf	fn up
    $ sudo evtest
    No device specified, trying to scan all of /dev/input/event*
    Available devices:
    /dev/input/event0:	Apple Internal Keyboard / Trackpad
    /dev/input/event1:	MacBookPro17,1 Touch Bar
    /dev/input/event2:	Apple Internal Keyboard / Trackpad
    /dev/input/event3:	Apple SMC power/lid events
    /dev/input/event4:	MacBook Pro J293 Headphone Jack
    /dev/input/event5:	Dynamic Function Row Virtual Input Device
    /dev/input/event6:	keyd virtual keyboard
    /dev/input/event7:	keyd virtual pointer
    Select the device event number [0-7]: 6
    Input driver version is 1.0.1
    Input device ID: bus 0x3 vendor 0xfac product 0xade version 0x0
    Input device name: "keyd virtual keyboard"
    Supported events:
      Event type 0 (EV_SYN)
      <truncated>
    Properties:
    Testing ... (interrupt to exit)
    Event: time 1732936447.877785, type 1 (EV_KEY), code 28 (KEY_ENTER), value 0
    Event: time 1732936447.877785, -------------- SYN_REPORT ------------
    Event: time 1732936448.119416, type 1 (EV_KEY), code 254 (?), value 1
    Event: time 1732936448.119416, -------------- SYN_REPORT ------------
    Event: time 1732936448.271307, type 1 (EV_KEY), code 254 (?), value 0
    $ sudo systemctl stop keyd
    $ sudo keyd monitor
    device added: 05ac:0341:c3080866 Apple Internal Keyboard / Trackpad (/dev/input/event0)
    device added: 0000:0000:1bf3eacc MacBookPro17,1 Touch Bar (/dev/input/event1)
    device added: 05ac:0341:3179765c Apple Internal Keyboard / Trackpad (/dev/input/event2)
    device added: 1209:316e:2b020ae1 Dynamic Function Row Virtual Input Device (/dev/input/event5)
    Apple Internal Keyboard / Trackpad	05ac:0341:c3080866	enter up
    Apple Internal Keyboard / Trackpad	05ac:0341:c3080866	fn down
    Apple Internal Keyboard / Trackpad	05ac:0341:c3080866	fn up
    $ sudo evtest
    No device specified, trying to scan all of /dev/input/event*
    Available devices:
    /dev/input/event0:	Apple Internal Keyboard / Trackpad
    /dev/input/event1:	MacBookPro17,1 Touch Bar
    /dev/input/event2:	Apple Internal Keyboard / Trackpad
    /dev/input/event3:	Apple SMC power/lid events
    /dev/input/event4:	MacBook Pro J293 Headphone Jack
    /dev/input/event5:	Dynamic Function Row Virtual Input Device
    Select the device event number [0-5]: 0
    Input driver version is 1.0.1
    Input device ID: bus 0x1c vendor 0x5ac product 0x341 version 0x175
    Input device name: "Apple Internal Keyboard / Trackpad"
    Supported events:
      Event type 0 (EV_SYN)
      <truncated>
    Properties:
    Testing ... (interrupt to exit)
    Event: time 1732936876.378020, type 4 (EV_MSC), code 4 (MSC_SCAN), value 70028
    Event: time 1732936876.378020, type 1 (EV_KEY), code 28 (KEY_ENTER), value 0
    Event: time 1732936876.378020, -------------- SYN_REPORT ------------
    Event: time 1732936877.134727, type 4 (EV_MSC), code 4 (MSC_SCAN), value ff0003
    Event: time 1732936877.134727, type 1 (EV_KEY), code 464 (KEY_FN), value 1
    Event: time 1732936877.134727, -------------- SYN_REPORT ------------
    Event: time 1732936877.290671, type 4 (EV_MSC), code 4 (MSC_SCAN), value ff0003
    Event: time 1732936877.290671, type 1 (EV_KEY), code 464 (KEY_FN), value 0
    
  5. ftelnov commented on Dec 12, 2024

    @ftelnov

    +1. Keyd correctly detects FN key, but after remapping it stops working as it worked before - for instance, I can't use top row with it.

  6. ftelnov commented on Dec 12, 2024

    @ftelnov

    Any progress or workaround on this? Maybe we can somehow tell keyd that we remap fn to specific keycode? Is operation with keycodes in keyd even possible?

  7. Cal-Nine commented on Oct 17, 2025

    @Cal-Nine

    Same thing for me, trying to use keyd and tiny-dfr. Perhaps a passthrough or ignore key option?

    Apparently the Apple fn/Globe Key has some peculiarities, which are beyond me technically, but it is different to the fn key (or seems like it sends its own code in addition to fn?). It does seem like it has been added to QMK and some third party keyboards are able to use it.

  8. Alper-Celik commented on Jul 2, 2026

    @Alper-Celik

    Yay i fixed it, after some debugging and back and forth with LLM i fixed it. problem was keyd wasnt passing fn key properly on virtual uinput device.

    feel free to test my patch #1294

  9. celesrenata commented on Jul 9, 2026

    @celesrenata
    Author

    Wish I could! My T2 mac died :(

  10. riturajborpujari commented on Sep 7, 2026

    @riturajborpujari

    @Alper-Celik Looked at your fix. Seems clear - keyd wasn't registering the key bit before registering with uinput

    Tested on my Macbook M1.

    $ sudo libinput debug-events
    event4 KEYBOARD_KEY  +0.421s KEY_FN(464) pressed
    event4 KEYBOARD_KEY  +0.901s KEY_FN(464) released
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions