<?php include "HEADER.php"; ?>

<h1>Customizing your keyboard under Linux</h1>

<p>Make Debian default to caps lock as control system-wide by editing `/etc/default/keyboard`:</p>

<pre>XKBOPTIONS="ctrl:nocaps"</pre>

<h2>The new way: setxkbmap</h2>

<p>See SETXKBMAP(1) and XKEYBOARD-CONFIG(7).</p>

<p>Show the current config with <code>setxkbmap -query</code> or <code>setxkbmap -print -verbose 10</code>.</p>

<p>Look at the available options in <code>/usr/share/X11/xkb/rules/evdev.lst</code>. Here are some I find useful:</p>

<pre>ctrl:nocaps          Caps Lock as Ctrl
ctrl:lctrl_meta      Left Ctrl as Meta
shift:both_capslock  Both Shift keys together toggle Caps Lock</pre>

<p>or</p>

<pre>caps:hyper     Caps Lock as Hyper_L</pre>

<p>or</p>

<pre>altwin:swap_alt_win    Alt is swapped with Win</pre>

<p>Invoke options like:</p>

<pre>setxkbmap -model pc105 -layout us -option \
-option ctrl:nocaps -option ctrl:lctrl_meta -option shift:both_capslock</pre>

<p>(The empty <code>-option</code> argument resets things, so we start from a clean slate.)</p>

<p>There are some things <code>setxkbmap</code> can't do with simple options. For those things, create <code>~/.xkb/symbols/mysymbols</code> and <code>~/.xkb/keymap/mykeymap</code>.</p>

<p>Apply the custom keymap with: </code>xkbcomp -I$HOME/.xkb ~/.xkb/keymap/mykeymap $DISPLAY</code>.</p>

<p>Also see the man pages for <code>xkeyboard-config</code> and <code>setxkbmap</code> and <code>keyboard</code>.</p>

<p><strong>N.B.</strong> I've found xkb to be a little flaky. For example, if I set keyboard options in my .xsession with xsetkbmap, those options get reset to defaults in the keyboard is unplugged/plugged. As an alternative, system-wide defaults can be set in <code>/etc/defaults/keyboard</code>.</p>

<h2>The old way: xmodmap</h2>

<p><code>xmodmap</code> maps the KeyCodes of physical keys on your keyboard to what KeySym value get sent when you press that key.</p>

<p>Determine what key is what by running <code>xev</code> from a terminal. It will show you the keycode for any key you press. <code>xmodmap -pk</code> may also be useful; it prints the current key mappings. (Using <code>xmodmap -pke</code> gives the same information as a list of commands that can be fed back to <code>xmodmap</code> like <code>xmodmap -e 'keycode  47 = semicolon colon semicolon colon'</code>.)</p>

<h3>Modifier keys</h3>

<p>Print the keycodes and keysym values for modifier keys like Caps Lock, Alt, and Control with <code>xmodmap -pm</code>. Changing modifier keys is slightly different from changing other keys, using clear, remove, and add.</p>

<h3>Saving your changes</h3>

<p>Once you know what you want to do with <code>xmodmap</code>, either save your <code>xmodmap</code> commands to the beginning of your <code>.xsession</code> file if you only have one or two changes, or keep your entire key mapping in its own file by adding this to your<code>.xsession</code>:</p>

<pre>if [ -s ~/.Xmodmap ]; then
    xmodmap ~/.Xmodmap
fi</pre>

<p>...and having <code>xmodmap</code> create a <code>.Xmodmap</code> file b:verbose set buftypeased on your current settings:</p>

<pre>xmodmap -pke &gt; ~/.Xmodmap</pre>

<?php include "../FOOTER.php"; ?>
