Skip to content

Instantly share code, notes, and snippets.

@imaami
Last active January 15, 2019 17:05
Show Gist options
  • Save imaami/84018d262d1b9e4a9afb70ce38de8623 to your computer and use it in GitHub Desktop.
Save imaami/84018d262d1b9e4a9afb70ce38de8623 to your computer and use it in GitHub Desktop.
Create xmodmaprc to make VNC usable
#!/bin/bash
#
# This script executes `xmodmap -pke', modifies the output,
# and prints the result to stdout so that it can be used as
# an xmodmaprc file.
#
# The resulting keymap has AltGr remapped to Mode_switch.
# Existing AltGr-modified key combinations are changed to
# match the new mapping.
#
# This basically just automates a solution outlined by Michael
# Mrozek in this post: https://unix.stackexchange.com/a/302591
#
xmodmap -pke \
| sed -r 's, +, ,g' \
| cut -d' ' -f2,4- \
| while read line; do
k=($(echo $line))
if (( "${k[0]}" == 108 )); then
k=(108 Mode_switch Mode_switch Mode_switch Mode_switch)
elif (( "${#k[@]}" >= 6 )) &&
[[ "${k[1]}" != "${k[5]}" &&
"${k[5]}" != 'NoSymbol' ]]; then
k[3]="${k[5]}"
fi
echo keycode ${k[0]} = ${k[1]} ${k[2]} ${k[3]} ${k[4]} ${k[5]} ${k[6]} ${k[7]}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment