Multimedia Keys

From SUSE Wiki

Jump to: navigation, search

Type: Howto

Tested Versions: 10.1

Written By: Leshiy

Further Modifications By: Sebastian Kraiker

Image:Bell.pngThis article was/is a Featured Article. It therefore has recieved much laud in terms of quality and content.


This article is aimed towards people that have keyboards with extra multimedia keys. By default, these keys are not activated, although it is not very difficult to do so.

Contents

Packages Needed

  • X11
  • xbindkeys
  • Terminal (xterm or Konsole, for example)

Preamble

First, all of the keys on the keyboard are assigned to a particular "keycode". If you open console and type

$ xmodmap -pke

you should see something like this:

keycode  23 = Tab ISO_Left_Tab
keycode  24 = q Q at Greek_OMEGA at Greek_OMEGA
keycode  25 = w W lstroke Lstroke lstroke Lstroke
keycode  26 = e E
keycode  27 = r R paragraph registered paragraph registered
keycode  28 = t T tslash Tslash tslash Tslash
keycode  29 = y Y leftarrow yen leftarrow yen
keycode  30 = u U downarrow uparrow downarrow uparrow

Now we need to find out what keycodes your keyboard generates when you press your multimedia keys. To do this, open console again and type

$ xev

this will open another window where your X server will register all key strokes and mouse movement within the window and will output in the terminal window. For example if you press "a" you should see something like this:

KeyPress event, serial 28, synthetic NO, window 0x7200001,
   root 0x3e, subw 0x0, time 1795907, (240,428), root:(244,491),
   state 0x10, keycode 38 (keysym 0x61, a), same_screen YES,
   XLookupString gives 1 bytes: (61) "a"
   XmbLookupString gives 1 bytes: (61) "a"
   XFilterEvent returns: False
KeyRelease event, serial 31, synthetic NO, window 0x7200001,
   root 0x3e, subw 0x0, time 1795970, (240,428), root:(244,491),
   state 0x10, keycode 38 (keysym 0x61, a), same_screen YES,
   XLookupString gives 1 bytes: (61) "a"

Here you can see that keycode for letter "a" is 38. Try pressing your multimedia keys and make note of their keycodes.

Setting Up

Now you need to open your favourite editor (like kate or kwrite) and create a new file called .Xmodmap in the /home/<user>/ directory, where <user> is your user name. N.B. Prefix "." in front of files or folders makes them hidden from view. To see them in Konqueror, go to "View > Show Hidden Files". In the new file copy all the keycodes from terminal after you typed "xmodmap -pke". Now find the corresponding keycodes with the ones you made note of earlier and fill them in like this :

keycode (number) = (key name)

you can use any name, but there are already defined names that describe some functions like "XF86Media, XF86Calculator etc.) The full list can be seen in /usr/X11R6/lib/X11/XKeysymDB. Once completed, we can load the new keymap. Open terminal and type

$ xmodmap /home/<user>/.Xmodmap

SUSE will now load these settings during startup.

On my system only VolumeUp VolumeDown and Mute worked, so if you are like me please read on.

Further Binding

Now you need to bind the keys defined in the ".Xmodmap" to particular applications and actions.

In KDE applications it is often possible to define global shortcuts using a convenient dialogue in the settings menu. E.g. amarok offers this possibility. This works now that the newly named keys are "known" to the system.

Another way is to use xbindkeys package. Open your favourite editor again and create a new file in /home/<user>/ directory called ".xbindkeysrc". There you have to first type the command you would type in the terminal to launch particular applications. For example if you want to launch amarok you would type "amarok", type that command in "" above the name you gave to it in the .Xmodmap. Commands for applications can be found if you press right mouse button on the application icon > Configure Button > Application Tab > Command field. i.e. here is what my file looks like:

"evolution -c mail"
XF86Mail
"xcalc"
XF86Calculator
"amixer set Master 1+"
XF86AudioRaiseVolume
"amixer set Master 1-"
XF86AudioLowerVolume
"amarok --play"
XF86AudioPlay
"amarok --stop"
XF86AudioStop
"amarok --next"
XF86AudioNext
"amarok --previous"
XF86AudioPrev
"firefox"
XF86HomePage
"amarok"
XF86Music

Once completed, you'll need to bind the keys in your .Xmodmap file to commands in your .xbindkeysrc file. to do this simply type

$ xbindkeys

in terminal window. All the keys that were bound and defined should work now. However, SUSE doesn't automatically run the "xbindkeys" command on start up. There are several ways to work around this, my preferred method is to use a file called ".xinitrc.template" in your home folder. Keep all the content of the file and just rename it to ".xinitrc" (It should still be a Shell Script). Now add following command after

#
# Add your own lines here...
#

add

xbindkeys

Now save and restart X. All your keys should be bound to the desired applications.

Troubleshooting

Problem: After restarting, you cannot get a certain application to start-up when it's button is pressed.
Possibile solution(s): Check in .Xmodmap that two keycodes have not been assigned the same name.

Problem: Upon pressing a button, an application other than that which you set is started (i.e. there are overriding settings elsehwere).
Possibile solution(s): under KDE and Gnome, this problem is caused by the default applications used by GUI. To solve this, change the adjustment in control panel (ex : for email, KDE use KMail ; if you want use Thunderbird upon pressing a button, change this in the KDE control panel).

Personal tools