Skip to content

Instantly share code, notes, and snippets.

@joshskidmore
Created July 5, 2019 14:56
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save joshskidmore/f8599610da3308613cddcaf46a701ecc to your computer and use it in GitHub Desktop.
Uses xmodmap + xcape to use the MicroPC's bottom row a bit more efficiently
#!/usr/bin/env bash
# resets keyboard; kills all running instances of xcape
reset_kbd () {
local xcape_cnt=$(pgrep xcape | wc -l)
echo " - reset_kbd"
echo " - killing $xcape_cnt instances of xcape"
setxkbmap -layout us
killall xcape
}
# swaps the super key with alt/meta
super_alt_swap() {
echo " - super_alt_swap"
xmodmap -e 'keycode 64 = Super_L'
xmodmap -e 'keycode 133 = Alt_L'
xmodmap -e 'clear mod1'
xmodmap -e 'clear mod4'
xmodmap -e 'add mod4 = Super_L'
}
# when capslk is held, it acts as ctrl
# when capslk is tapped, it acts as esc
caps_to_ctrl() {
echo " - caps_to_ctrl"
xmodmap -e 'clear lock'
xmodmap -e 'clear control'
xmodmap -e 'keycode 66 = Control_L'
xmodmap -e 'add control = Control_L Control_R'
xcape -e 'Control_L=Escape' -t 175
}
# when the /+? key is held, it acts as super
# when the /+? key is tapped, it acts as a normal /+? key
slash_to_super () {
echo " - slash_to_super"
xmodmap -e 'keycode 61 = Super_R'
xmodmap -e 'keycode any = slash question'
xcape -e 'Super_R=slash|question' -t 175
}
# when the \+| key is held, it acts as ctrl
# when the \+| key is tapped, it acts as a normal \+| key
bar_to_ctrl() {
echo " - bar_to_ctrl"
xmodmap -e 'keycode 51 = Hyper_L'
xmodmap -e 'remove mod4 = Hyper_L'
xmodmap -e 'add Control = Hyper_L'
xmodmap -e 'keycode any = backslash bar'
xcape -e 'Hyper_L=backslash|bar' -t 175
}
# when left-hand super key is held, it acts normal
# when left-hand super key is tapped, it triggers XF86Documents
# which is a unique key not used on the MPC and can be bound to anything -
# like a chat app
alt_to_chat() {
echo " - alt_to_chat"
xcape -e "Alt_L=XF86Documents" -t 175
}
# when left-hand alt/meta key is held, it acts normal
# when left-hand alt/meta key is tapped, it triggers F12
# which can be bound to something like a guake-like terminal
super_to_f12() {
echo " - super_to_f12"
xcape -e 'Super_L=F12' -t 175
}
# actually call the functions (allows ordering and temporarily disabling)
# if needed
reset_kbd
caps_to_ctrl
super_alt_swap
bar_to_ctrl
slash_to_super
alt_to_chat
super_to_f12
notify-send "Keyboard Configured/Reset"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment