How to customize keyboard mappings in X

From NetBSD Wiki

Jump to: navigation, search


How to readjust your keyboard map to your liking.

Contents

Introduction

Sometimes, esp. when working in an X environment, the default keyboard layouts aren't enough...

xbindkeys

  • Program that allows you to launch shell commands with your keyboard or mouse under X. It links commands to keys or mouse buttons.
  cd /usr/pkgsrc/x11/xbindkeys
  make install clean

Create a default file

  xbindkeys --defaults > $HOME/.xbindkeysrc

Grab a key code

  xbindkeys -k

or

  xbindkeys -mk

for multi-keys respectively.

Examples

  • .xbindkeysrc
  # control+shift+d starts an xterm (it's a comment)
  "xterm"
    control+shift + q
  # Menu key starts xbindkeys_show
  "xbindkeys_show"
    Menu
  # Control + mouse button 1 starts an xterm
  "xterm"
    Control + b:1
  # Control+Shift+a  release event starts rxvt
  "rxvt"
    release+control+shift + a
  # Control + mouse button 2 release event starts rxvt
  "rxvt"
    Control + b:2 + Release

xmodmap

  • X utility for modifying keymaps and pointer button mappings. Call it from .xinitrc or .xsession, depending on whether you use 'startx' or the X display manager, like:
   xmodmap ~/.xmodmaprc

German umlauts with en_US keyboards

  • I use the [right-Alt]+[vowel] key combination. For that, add the following to your .xmodmaprc
   ! Alt_R + aAeEoOuUs für Umlaute auf US-Tastaturen.
   clear mod1             
   add mod1 = Alt_L             
   add mod3 = Alt_R                
   keysym Alt_R = Mode_switch               
   keysym  u    = u U udiaeresis      Udiaeresis              
   keysym  a    = a A adiaeresis      Adiaeresis              
   keysym  o    = o O odiaeresis      Odiaeresis                
   keysym  s    = s S ssharp            

Swap Caps_Lock and Control_L

  • This comes in handy esp. when using Emacs, screen and similar programs.
  ! Swap Caps_Lock and Control_L
  remove Lock = Caps_Lock
  remove Control = Control_L
  keysym Control_L = Caps_Lock
  keysym Caps_Lock = Control_L
  add Lock = Caps_Lock
  add Control = Control_L

Alternatively you can add in the InputDevice section of your keyboard in /etc/X11/xorg.conf (dunno if Xfree.conf works):

  Option  "XkbOptions"    "ctrl:swapcaps"

Mouse emulation mode with Num_Lock

  remove Lock = Num_Lock
  add Lock = Control+Mod2 + Num_Lock
Personal tools