Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save toneomgomg/fa58663e0c120e940be71f954afd3508 to your computer and use it in GitHub Desktop.
Save toneomgomg/fa58663e0c120e940be71f954afd3508 to your computer and use it in GitHub Desktop.
Remap the function keys on MS Natural Ergonomic Keyboard 4000 to ALWAYS be function keys.
#!/usr/bin/env bash
# Copyright (c) 2019-2020 Thomas Hellström <rel@xed.se>
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
cat <<EOF | sudo tee /etc/udev/hwdb.d/61-microsoft-natural-ergonomic-keyboard-4000.hwdb
#: ============================================================================
#: Microsoft Natural Ergonomic Keyboard 4000
#: ============================================================================
evdev:input:b*v045Ep00DB*
# ----------------------------------------------------------------------------
#
# Remap the utterly USELESS secondary function keys to act as normal function
# keys. (Seriously, Microsoft, what were you smoking?)
#
# help => f1
# undo => f2
# redo => f3
# new => f4
# open => f5
# close => f6
# reply => f7
# fwd => f8
# send => f9
# spell => f10 (This one is impossible to remap with xkb without this hack)
# save => f11
# print => f12
#
# ----------------------------------------------------------------------------
KEYBOARD_KEY_c0095=f1
KEYBOARD_KEY_c021a=f2
KEYBOARD_KEY_c0279=f3
KEYBOARD_KEY_c0201=f4
KEYBOARD_KEY_c0202=f5
KEYBOARD_KEY_c0203=f6
KEYBOARD_KEY_c0289=f7
KEYBOARD_KEY_c028b=f8
KEYBOARD_KEY_c028c=f9
KEYBOARD_KEY_c01ab=f10
KEYBOARD_KEY_c0207=f11
KEYBOARD_KEY_c0208=f12
EOF
# Update udevadm
sudo udevadm hwdb --update
sudo udevadm control --reload
# 'Unplug and replug' the keyboard
for X in /sys/bus/usb/devices/*; do
idVendor=$(cat "$X/idVendor" 2>/dev/null)
idProduct=$(cat "$X/idProduct" 2>/dev/null)
if [ "$idVendor" == "045e" ] && [ "$idProduct" == "00db" ]; then
sudo sh -c "echo 0 > $X/authorized"
sudo sh -c "echo 1 > $X/authorized"
fi
done
# Sing a happy song!
cat <<EOF
===============================================================================
Installation done! Your function keys are now working as intended.
===============================================================================
EOF
Copy link

ghost commented May 11, 2020

Worked like a charm. Many thanks for this.

Microsoft makes great hardware, but they manage to mess up even the bit of firmware that runs on it.

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