Inhaltsverzeichnis

xbindkeys

XBindKeys ist ein Programm das den Aufruf von Shell Kommandos per Tastatur oder Maus unter X-Windows ermöglicht. Hierzu werden in einer Konfigurationsdatei Kommandos mit Tasten oder Maustasten verknüpft. Es ist unabhängig vom Window-Manager und kann alle Keyboard Tasten abfangen.

Herunterladen

XBindKeys kann von folgenden Seiten heruntergeladen werden:

Installation

Ab hier werden root-Rechte zur Ausführung der nachfolgenden Befehle benötigt. Um root zu werden geben Sie bitte folgenden Befehl ein:

$ su -
Password: 

Ein mögliche Installation wäre das RPM-Paket mit folgendem Befehl zu installieren, ausgehend davon das das RPM-Paket sich im Verzeichnis /tmp befindet:

# yum localinstall --nogpgcheck /tmp/xbindkeys-1.8.2-1.el5.rf.i386.rpm

Die Installation von XBindKeys bringt folgende Dateien mit sich:

Der Inhalt des RPM-Paketes sieht wie folgt aus und kann mit folgendem Befehl nach der Installation angesehen werden:

# rpm -qil xbindkeys 
Name        : xbindkeys                    Relocations: (not relocatable)
Version     : 1.8.2                             Vendor: Dag Apt Repository, http://dag.wieers.com/apt/
Release     : 1.el5.rf                      Build Date: Wed 11 Jun 2008 03:02:13 AM CEST
Install Date: Fri 28 Nov 2008 12:14:24 PM CET      Build Host: lisse.leuven.wieers.com
Group       : User Interface/X              Source RPM: xbindkeys-1.8.2-1.el5.rf.src.rpm
Size        : 89850                            License: GPL
Signature   : DSA/SHA1, Wed 11 Jun 2008 03:27:12 AM CEST, Key ID a20e52146b8d79e6
Packager    : Dag Wieers <dag@wieers.com>
URL         : http://hocwp.free.fr/xbindkeys/xbindkeys.html
Summary     : Binds keys or mouse buttons to shell commands under X
Description :
xbindkeys is a program that allows you to launch shell commands
with your keyboard or mouse under X. It links commands to keys
or mouse buttons using a simple configuration file, and is
independant of the window manager.
/usr/bin/xbindkeys
/usr/bin/xbindkeys_show
/usr/share/doc/xbindkeys-1.8.2
/usr/share/doc/xbindkeys-1.8.2/AUTHORS
/usr/share/doc/xbindkeys-1.8.2/BUGS
/usr/share/doc/xbindkeys-1.8.2/COPYING
/usr/share/doc/xbindkeys-1.8.2/ChangeLog
/usr/share/doc/xbindkeys-1.8.2/INSTALL
/usr/share/doc/xbindkeys-1.8.2/NEWS
/usr/share/doc/xbindkeys-1.8.2/README
/usr/share/doc/xbindkeys-1.8.2/TODO
/usr/share/man/man1/xbindkeys.1.gz
/usr/share/man/man1/xbindkeys_show.1.gz

Konfiguration

Aus Gründen des Komforts, soll XBindKeys automatisch beim Starten des Window-Managers, hier in z.B. GNOME eingebunden werden. Außerdem soll in diesem Beispiel durch drücken einer der beiden Windows-Tasten der GNOME-Bildschirmschoner und das dadurch verbundene Sperren des Bildschirms gestartet werden.

Einbinden in GNOME

Dazu muss im HOME-Verzeichnis des entsprechenden Benutzers folgendes Verzeichnis genutzt bzw. angelegt werden, falls dieses noch nicht vorhanden sein sollte:

Falls dieses Verzeichnis noch nicht existieren sollte, kann mit folgendem Befehl in das Verzeichnis /home/<benutzer>/.config gewechselt werden:

# cd ~/.config

Als nächstes muss ein Verzeichnis mit dem Namen autostart mit folgendem Befehl angelegt werden:

# mkdir autostart

Anschließend kann mit nachfolgendem Befehl eine Datei mit dem Namen

angelegt werden:

# touch xbindkeys.desktop

Abschließend muss die Datei durch einen Editor Ihrer Wahl, z.B. vi, it folgendem Inhalt gefüllt werden:

[Desktop Entry]
Name=XBindKeys
Encoding=UTF-8
Version=1.0
Exec=/usr/bin/xbindkeys
X-GNOME-Autostart-enabled=true

Somit sollte bei jedem automatischen Start des Window-Managers, hier in diesem Beispiel GNOME, auch XBindKeys mit gestartet werden.

Konfigurationsdatei: .xbindekeysrc

Es gibt eine sehr einfache Möglichkeit eine erste Standard-Konfigrationsdatei im HOME-Verzeichnis des jeweiligen Benutzers zu erzeugen. Diese Möglichkeit bringt XBIndKeys mit.

Zuerst muss wieder in das jeweilige HOME-Verzeichnis des Benutzer mit folgendem Befehl gewechselt werden:

# cd ~

Im HOME-Verzeichnis kann über den Aufruf von /usr/bin/xbindkeys mit nachfolgenden Parametern eine Standard-Konfigurationsdatei erzeugt werden:

# /usr/bin/xbindkeys --defaults > ~/.xbindkeysrc

Diese Konfigurationsdatei ist eine versteckte Datei. Über folgenden Befehl kann die Datei .xbindkeysrc im HOME-Verzeichnis jedoch angezeigt werden:

# # ll -la .xbindkeysrc
-rw-r--r-- 1 root root 1773 Nov 28 14:48 .xbindkeysrc

Der Inhalt der Konfigurationsdatei sollte in etwa wie folgt aussehen:

# For the benefit of emacs users: -*- shell-script -*-
###########################
# xbindkeys configuration #
###########################
#
# Version: 1.8.2
#
# If you edit this file, do not forget to uncomment any lines
# that you change.
# The pound(#) symbol may be used anywhere for comments.
#
# To specify a key, you can use 'xbindkeys --key' or
# 'xbindkeys --multikey' and put one of the two lines in this file.
#
# The format of a command line is:
#    "command to start"
#       associated key
#
#
# A list of keys is in /usr/include/X11/keysym.h and in
# /usr/include/X11/keysymdef.h
# The XK_ is not needed.
#
# List of modifier:
#   Release, Control, Shift, Mod1 (Alt), Mod2 (NumLock),
#   Mod3 (CapsLock), Mod4, Mod5 (Scroll).
#
 
# The release modifier is not a standard X modifier, but you can
# use it if you want to catch release events instead of press events
 
# By defaults, xbindkeys does not pay attention with the modifiers
# NumLock, CapsLock and ScrollLock.
# Uncomment the lines above if you want to pay attention to them.
 
#keystate_numlock = enable
#keystate_capslock = enable
#keystate_scrolllock= enable
 
# Examples of commands:
 
"xbindkeys_show" 
  control+shift + q
 
# set directly keycode (here control + f with my keyboard)
"xterm"
  c:41 + m:0x4
 
# specify a mouse button
"xterm"
  control + b:2
 
#"xterm -geom 50x20+20+20"
#   Shift+Mod2+alt + s
#
## set directly keycode (here control+alt+mod2 + f with my keyboard)
#"xterm"
#  alt + c:0x29 + m:4 + mod2
#
## 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
 
##################################
# End of xbindkeys configuration #
##################################

Folgende Ergänzungen an der ersten Standard-Konfigurationsdatei müssen vorgenommen werden, um zu realisieren, dass beim drücken einer der beiden Windows-Tasten der GNOME-Bildschirmschoner und das dadurch verbundene Sperren des Bildschirms gestartet wird:

# gnome screensaver lock
"gnome-screensaver-command --lock"
    m:0x10 + c:115
    Mod2 + Super_L
 
"gnome-screensaver-command --lock"
    m:0x10 + c:116
    Mod2 + Super_R

Eine Mögliche finale Konfiguratiosndatei könnte dann wie folgt aussehen:

# For the benefit of emacs users: -*- shell-script -*-
###########################
# xbindkeys configuration #
###########################
#
# Version: 1.8.2
#
# If you edit this file, do not forget to uncomment any lines
# that you change.
# The pound(#) symbol may be used anywhere for comments.
#
# To specify a key, you can use 'xbindkeys --key' or
# 'xbindkeys --multikey' and put one of the two lines in this file.
#
# The format of a command line is:
#    "command to start"
#       associated key
#
#
# A list of keys is in /usr/include/X11/keysym.h and in
# /usr/include/X11/keysymdef.h
# The XK_ is not needed.
#
# List of modifier:
#   Release, Control, Shift, Mod1 (Alt), Mod2 (NumLock),
#   Mod3 (CapsLock), Mod4, Mod5 (Scroll).
#
 
# The release modifier is not a standard X modifier, but you can
 
 
 
# use it if you want to catch release events instead of press events
 
# By defaults, xbindkeys does not pay attention with the modifiers
# NumLock, CapsLock and ScrollLock.
# Uncomment the lines above if you want to pay attention to them.
 
#keystate_numlock = enable
#keystate_capslock = enable
#keystate_scrolllock= enable
 
# Examples of commands:
 
"xbindkeys_show" 
  control+shift + q
 
# set directly keycode (here control + f with my keyboard)
#"xterm"
#  c:41 + m:0x4
 
# specify a mouse button
#"xterm"
#  control + b:2
 
# gnome screensaver lock
"gnome-screensaver-command --lock"
    m:0x10 + c:115
    Mod2 + Super_L
 
"gnome-screensaver-command --lock"
    m:0x10 + c:116
    Mod2 + Super_R
 
#"xterm -geom 50x20+20+20"
#   Shift+Mod2+alt + s
#
## set directly keycode (here control+alt+mod2 + f with my keyboard)
#"xterm"
#  alt + c:0x29 + m:4 + mod2
#
## 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
 
##################################
# End of xbindkeys configuration #
##################################

Erster Test

Um zu testen, ob alles geklappt hat, kann die Tastenkombination [Control+Shift+q] bzw. auf deutsch [Strg+Hochstellen+q] gedrückt werden. Daraufhin sollte sich ein X-Fenster mit der aktuellen Konfiguration von XBindKeys öffnen, wie hier dargestellt:

xbindkeys_show

Hilfreiche Befehle

xbindkeys -s

Mit der Eingabe dieses Befehls, wird die aktuelle Konfiguration der Tasten- und Maustastenbelegung von XBindKeys angezeigt:

# xbindkeys -s
"xbindkeys_show"
    Control+Shift + q
"gnome-screensaver-command --lock"
    m:0x0 + c:115
    Super_L
"gnome-screensaver-command --lock"
    m:0x0 + c:116
    Super_R

xbindkeys -k

Mit der Eingabe dieses Befehls, wird ein X-Fenster geöffnet und es kann eine Tasten- oder Maustastenkombination getestet werden. Danach beendet sich das Programm wieder und es wird eine Vorlage für die soeben gerade gedrückte Tasten- oder Maustastenkombination angezeigt:

XBindKey: Hit a key

# xbindkeys -k
Press combination of keys or/and click under the window.
You can use one of the two lines after "NoCommand"
in $HOME/.xbindkeysrc to bind a key.
"(Scheme function)"
    m:0x0 + c:115
    Super_L

xbindkeys -mk

Mit der Eingabe dieses Befehls, wird ein X-Fenster geöffnet und es können mehrere Tasten- oder Maustastenkombination getestet werden. Danach kann das Programm mit der Eingabe des einfachen Buchstabens „q“ beendet werden. Während der Eingabe der Tasten- oder Maustastenkombinationen wurden diese als Vorlage für die soeben gerade gedrückte Tasten- oder Maustastenkombination in der shell angezeigt:

XBindKey: Hit a key

# xbindkeys -mk
Press combination of keys or/and click under the window.
You can use one of the two lines after "NoCommand"
in $HOME/.xbindkeysrc to bind a key.
 
--- Press "q" to stop. ---
"(Scheme function)"
    m:0x0 + c:115
    Super_L
"(Scheme function)"
    m:0x0 + c:116
    Super_R
"(Scheme function)"
    m:0x10 + c:24
    Mod2 + q