Skip to content

Instantly share code, notes, and snippets.

@andrejcremoznik
Last active November 13, 2024 05:56
Show Gist options
  • Save andrejcremoznik/e56234138305226abd41fe4d1d2561a3 to your computer and use it in GitHub Desktop.
Save andrejcremoznik/e56234138305226abd41fe4d1d2561a3 to your computer and use it in GitHub Desktop.
Logitech K780 switch media and function keys on linux

Media/function keys on K780

K780 doesn't have a hard switch to lock the function keys. Logitech provides a utility to do this on Windows and iOS but not on Linux. You need to manually remap the keys.

Below works for Arch Linux, other systemd based distros should be about the same.

There's a problem with the F1-F3 keys as they're hardware specific and don't emit an event if pressed on their own and therefore can't be remapped. I might be wrong as I haven't spend any time on researching that.

Edit: about htat, see @tangruize comments below https://gist.github.com/andrejcremoznik/e56234138305226abd41fe4d1d2561a3#gistcomment-3390489

Create file /etc/udev/hwdb.d/95-k780.hwdb

# Logitech K780 map:
# Fn + F4/F5/F6 ==> F4/F5/F6
evdev:input:b0003v046Dp405B*
  KEYBOARD_KEY_c0223=f4
  KEYBOARD_KEY_70065=f5
  KEYBOARD_KEY_c0224=f6

Rebuild hwdb.bin and apply new keys

sudo systemd-hwdb update
sudo udevadm trigger

Make permanent

Make sure the ConditionNeedsUpdate=/etc is commented out in /usr/lib/systemd/system/systemd-hwdb-update.service. If it isn't create an override:

sudo systemctl edit --full systemd-hwdb-update.service

Comment out:
#ConditionNeedsUpdate=/etc

This creates a replacement systemd unit file in /etc/systemd/system/systemd-hwdb-update.service. If some update breaks anything related to this, remove it and recreate with systemctl edit like before.

Read more

@Roman2K
Copy link

Roman2K commented Jul 17, 2022

@tangruize Thanks for this concise solution and all the work that lead to it. Working perfectly for me!

I created an Arch PKGBUILD for it: Roman2K/arch-k780-fnkey

@tangruize
Copy link

The $SCRIPT_FILE can be simplified:
...

SUBSYSTEM=="hidraw", ACTION=="add", RUN+="$SCRIPT_FILE $name"

I found that it doesn't work sometimes (for bluetooth), and I improved it:

Delete the above rule and script file, and append below contents to /etc/udev/rules.d/00-k780.rules:

ACTION=="bind", KERNEL=="0005:046D:B33B*", SUBSYSTEM=="hid", RUN+="/bin/bash -c 'printf \"\x11\xff\x0c\x1d\" | cat - /dev/zero | dd of=/dev/$$(ls $$0/hidraw) count=20 iflag=count_bytes oflag=nonblock' %S%p"

@satmandu
Copy link

For what it is worth, my K780 & logitech devices report with slightly different USB addresses:

[ 3247.931263] logitech-djreceiver 0003:046D:C52B.0016: hiddev0,hidraw0: USB HID v1.11 Device [Logitech USB Receiver] on usb-0000:00:14.0-10/input2
[ 3248.043856] input: Logitech K780 as /devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.2/0003:046D:C52B.0016/0003:046D:405B.0017/input/input45
[ 3248.144901] logitech-hidpp-device 0003:046D:405B.0017: input,hidraw1: USB HID v1.11 Keyboard [Logitech K780] on usb-0000:00:14.0-10/input2:1
[ 3248.151857] input: Logitech M585/M590 as /devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.2/0003:046D:C52B.0016/0003:046D:406B.0018/input/input46
[ 3248.238210] logitech-hidpp-device 0003:046D:406B.0018: input,hidraw2: USB HID v1.11 Keyboard [Logitech M585/M590] on usb-0000:00:14.0-10/input2:2

So I modified the udev line from https://gist.github.com/andrejcremoznik/e56234138305226abd41fe4d1d2561a3?permalink_comment_id=4237309#gistcomment-4237309 accordingly:

ACTION=="bind", KERNEL=="0003:046D:405B*", SUBSYSTEM=="hid", RUN+="/bin/bash -c 'printf \"\x11\xff\x0c\x1d\" | cat - /dev/zero | dd of=/dev/$$(ls $$0/hidraw) count=20 iflag=count_bytes oflag=nonblock' %S%p"

But I still have to hit Fn-F2 to get F2 working.

@tangruize
Copy link

@satmandu Sorry I haven't used K780 in a while. You can try this script: https://gist.github.com/andrejcremoznik/e56234138305226abd41fe4d1d2561a3?permalink_comment_id=3390489#gistcomment-3390489. Since you're using USB receiver, I think Solaar might also help solve your problem if the script doesn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment