Skip to content

Instantly share code, notes, and snippets.

@lulu-berlin
Last active July 1, 2017 11:39
Show Gist options
  • Save lulu-berlin/637f162ddeaf8af3007083b8ca8adf8a to your computer and use it in GitHub Desktop.
Save lulu-berlin/637f162ddeaf8af3007083b8ca8adf8a to your computer and use it in GitHub Desktop.
How to fix numeric keypad on Linux not working with java applications
# credit to Peter L on StackOverflow:
# https://stackoverflow.com/questions/32753190/how-to-get-numeric-keypad-arrows-working-with-java-applications-on-linux/32753332#32753332
#!/bin/bash
SYMBOLS="/usr/share/X11/xkb/symbols"
KEYPAD="$SYMBOLS/keypad"
# create a backup in a temporary directory
TMP=$(mktemp -d)
cp "$KEYPAD" "$TMP/keypad"
# make a numbered backup in the original directory
sudo cp --backup=numbered "$TMP/keypad" "$SYMBOLS"
# fix the keypad file into the temporary directory
KEYS=("Up" "Down" "Left" "Right" "Home" "End" "Prior" "Next")
REGEX="s/KP_\("${KEYS[0]}$(printf "\|%s" "${KEYS[@]:1}")"\)/\1/g"
sed -e "$REGEX" "$KEYPAD" > "$TMP/keypad"
# overwrite the original keypad file
sudo cp "$TMP/keypad" "$KEYPAD"
# delete the temporary directory
rm -rf "$TMP"
# update the xkb symbols
sudo dpkg-reconfigure xkb-data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment