3

UPDATE: The method below seems to work fine if the Pi boots into commandline, but doesn't work if Pi is configured to boot into X.

====

I've just started dabbling with the Raspberry Pi. Being a frequent Vim user, as well as having bash/zsh in permanent vi mode. I'm wondering how I could map the Caps Lock key to ESC.

On my Macbook, I use Seil.

With the Pi, I've been modifying the /etc/default/keyboard file to achieve the same effect (and calling sudo dpkg-reconfigure keyboard-configuration after each config change). Unfortunately, it hasn't worked.

My keyboard file looks like this:

XKBMODEL="pc105"
XKBLAYOUT="us"
XKBVARIANT=""
XKBOPTIONS="caps:swapescape"

BACKSPACE="guess"

Has anyone successfully done this?

Ghanima
  • 15,855
  • 15
  • 61
  • 119
snowbound
  • 203
  • 1
  • 4
  • 10

2 Answers2

4

after booting into X you can use xmodmap to remap any key of your keyboard:

just use the command xmodmap -e 'keycode <value>=<action>'
and with xev you can get every keycode (and also the used action/keysym)


in your case it would probably be xmodmap -e 'keycode 66=Escape'.

by the way: if you don't want to type the command every time you login manually, you can insert the line into your .bash_profile and it is executed automatically with your login.


or if you want to remap more than one key you can create a file e.g. ~/.remap and insert something like this:

keycode 8 =
keycode 9 = Escape
keycode 10 = 1 plus plusminus infinity
keycode 11 = 2 quotedbl leftdoublequotemark rightdoublequotemark
keycode 12 = 3 asterisk numbersign leftcaret
keycode 13 = 4 ccedilla Ccedilla slash
keycode 14 = 5 percent bracketleft
keycode 15 = 6 ampersand bracketright
keycode 16 = 7 slash bar backslash
keycode 17 = 8 parenleft braceleft Ograve
keycode 18 = 9 parenright braceright Ocircumflex
keycode 19 = 0 equal notequal Uacute

in this file the keysyms (actions) are separated and the = is surrounded by a space!

within XServer you can use up to 4 keysyms triggered by the following:

  1. the action by normally pressing the key once
  2. the action when additionally Shift-Signal (normally Shift_L/Shift_R) is pressed
  3. the action when additionally Mode_switch-Signal (normally Alt_L/Alt_R) is pressed
  4. the action when additionally Shift and Mode_switch is pressed

for sure you can also remap Mode_switch with a line like this:

keycode <value> = Mode_switch

and then execute xmodmap ~/.remap in the terminal or add it to .bash_profile like the upper "one-key-command".

DJCrashdummy
  • 379
  • 1
  • 5
  • 17
  • Thanks @DJCrashdummy, the command xmodmap -e 'keycode 66=Escape' works. Unfortunately, I need to execute this command every time I start Terminal from within X. I boot by default to commandline, and start X from there when I need it. I've tried adding the xmodmap line to ~/.bash_profile and ~/.bashrc. Any suggestions? – snowbound May 31 '15 at 10:02
  • 1
    xmodmap only works when X is running! - if that's clear and .bash_profile still don't work as expected you can maybe try the global /etc/profile or /etc/bash.bashrc... – DJCrashdummy May 31 '15 at 11:28
  • It's all good. included xmodmap in .bashrc and it works fine now. Even know I boot to commandline, and start X from there. Thanks for the help! – snowbound May 31 '15 at 12:21
0

Following worked for me.

$ touch ~/.xmodmap
$ nano ~/.xmodmap

enter the following for ~/.xmodmap

clear Lock
keycode 0x42 = Escape

trigger the override with following

$ xmodmap ~/.xmodmap

if you like, you can place it in the end of either ~/.bashrc or ~/.bash_profile

if [ -f ~/.xmodmap ]; then
  xmodmap ~/.xmodmap
fi
mirageglobe
  • 101
  • 1