Xbindkeys

From ArchWiki
Revision as of 13:21, 23 October 2011 by Karol (Talk | contribs) (Undo revision 167161 by BertiBoeller (talk) we already have https://wiki.archlinux.org/index.php/Autostarting)

Jump to: navigation, search

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.


Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어


External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

Xbindkeys

Xbindkeys is a program that enables us to bind commands to certain keys or key combinations on the keyboard. Xbindkeys works with multimedia keys and is window manager / DE independent, so if you switch much, xbindkeys is very handy.

Installation

Xbindkeys is available in the extra repository:

# pacman -S xbindkeys

There is also a GUI for xbindkeys [1] which is in AUR.

Configuration

Create a file named Template:Filename in your home directory:

touch ~/.xbindkeysrc

Now you can either edit Template:Filename to set keybindings, or you can do that with the GUI.

Xbindkeysrc

To see the format of a configuration file entry, enter the following command:

xbindkeys -k

A blank window will pop up. Press the key(s) to which you wish to assign a command and xbindkeys will output a handy snippet that can be entered into Template:Filename. For example, while the blank window is open, press Alt + o to get the following output (results may vary):

"(Scheme function)"
    m:0x8 + c:32
    Alt + o

The first line represents a command. The second contains the state (0x8) and keycode (32) as reported by Template:Codeline. The third line contains the keysyms associated with the given keycodes. To use this output, copy the three lines to Template:Filename and replace "(Scheme function)" with the command you wish to perform. Here is an example configuration file that binds Fn key combos on a laptop to Template:Codeline commands that adjust sound volume. Note that pound (#) symbols can be used to create comments.

# Increase volume
"amixer set Master playback 1+"
    m:0x0 + c:123
    XF86AudioRaiseVolume

# Decrease volume
"amixer set Master playback 1-"
    m:0x0 + c:122
    XF86AudioLowerVolume

# Toggle mute
"amixer set Master toggle"
    m:0x0 + c:121
    XF86AudioMute
Tip: Use xbindkeys -mk to keep the key prompt open for multiple keypresses. Press q to quit.

GUI method

If you installed the xbindkeys_config package, just run:

xbindkeys_config

Usage

Once you're done configuring your keys, edit your Template:Filename and place

xbindkeys

before the line that starts your window manager or DE.

Simulating multimedia keys

The XF86Audio* and other multimedia keys[2] are pretty-much well-recognized by the major DEs. For keyboards without such keys, you can simulate their effect with other keys

# Decrease volume on pressing Super-minus
"amixer set Master playback 1-"
   m:0x50 + c:20
   Mod2+Mod4 + minus

However, to actually call the keys themselves you can use tools like xdotool[3] (its in [community]) and xmacro[4] (in the AUR). Unfortunately since you'd already be holding down some modifier key (Super or Shift, for example), X will see the result as Super-XF86AudioLowerVolume which won't do anything useful. Here's a script based on xmacro and xmodmap from the xorg-server-utils package for doing this[5].

#!/bin/sh
echo 'KeyStrRelease Super_L KeyStrRelease minus' | xmacroplay :0;
xmodmap -e 'remove Mod4 = Super_L';
echo 'KeyStrPress XF86AudioLowerVolume KeyStrRelease XF86AudioLowerVolume' | xmacroplay :0;
xmodmap -e 'add Mod4 = Super_L';

This works for calling XF86AudioLowerVolume once (assuming you're using Super-minus), but repeatedly calling it without releasing the Super key (like tapping on a volume button) doesn't work. If you'd like it to work that way, add the following line to the bottom of the script.

echo 'KeyStrPress Super_L' | xmacroplay :0

With this modified script, if you press the key combination fast enough your Super_L key will remain 'on' till the next time you hit it, which may result in some interesting side-effects. Just tap it again to remove that state, or use the original script if you want things to 'just work' and do not mind not multi-tapping on volume up/down.

These instructions are valid for pretty much any one of the XF86 multimedia keys (important ones would be XF86AudioRaiseVolume, XF86AudioLowerVolume, XF86AudioPlay, XF86AudioPrev, XF86AudioNext).