KDEMultimediaKeys

Revision 2 as of 2006-09-30 21:28:19

Clear message

Many people own multimedia keyboards, laptops with extra keys and/or are simply used to the Windows key opening the 'K' menu/Start Menu in Windows.

This Howto should, hopefully, provide you with the information needed in order to set up these keys to do what you want in KDE/Kubuntu.

The process is quite short and simple, if repetitive.

Stage 1 - Enabling the keys

  1. Open a Konsole (type Alt+F2, type konsole and click OK),
  2. ensure that you have the 'xev' package installed, sudo apt-get install xev

  3. launch xev in the konsole, xev

  4. you can safely ignore the text that appears, now press one of the keys you wish to use; you should see an output such as:{{{KeyPress event, serial 28, synthetic NO, window 0x2c00001,

    • root 0x135, subw 0x0, time 1344281323, (-281,237), root:(317,257),

      state 0x0, keycode 160 (keysym 0x0, NoSymbol), same_screen YES, XLookupString gives 0 bytes: XmbLookupString gives 0 bytes: XFilterEvent returns: False

KeyRelease event, serial 28, synthetic NO, window 0x2c00001,

  • root 0x135, subw 0x0, time 1344281323, (-281,237), root:(317,257),

    state 0x0, keycode 160 (keysym 0x0, NoSymbol), same_screen YES, XLookupString gives 0 bytes:}}} You are interested in the highlighted number.

  1. take a note of the number and which key it is,
  2. repeat the last 2 steps for each key you wish to assign/re-assign,
  3. create a new file ~/.Xmodmap as such: kate ~/.Xmodmap

  4. add a line for each of your keys as such: {{{keycode 160 = F13

keycode 161 = F14}}}The keycode's should be the ones you wrote down earlier. The F key numbers should be numbered after those that are actually present on your keyboard (so if you have a standard windows keyboard, you would have 12, if you have a mac keyboard you will have 16 so start at 17).

  1. save the file,
  2. create a new directory: mkdir ~/.kde/env

  3. create another new file ~/.kde/env/xmodmap.sh kate ~/.kde/env/xmodmap.sh

  4. enter the following into kate: {{{#!/bin/bash

xmodmap ~/.Xmodmap}}}

  1. save that file,
  2. make that file executable: chmod +x ~/.kde/env/xmodmap.sh

  3. execute that file: sh ~/.kde/env/xmodmap.sh

  4. load the KDE System Settings program from the 'K' menu,
  5. click on the 'Regional & Accessibility' icon.

You are now at the stage of being able to assign your keys to what you want them to do. The following sections will cover each possible action type you can assign.

Stage 2 - Setting the keys to an action

Standard Keyboard Shortcuts

If you wish, for example, to launch the 'K' menu by pressing a single button, eg. the Windows key, you should:

  1. Click on the 'Keyboard Shortcuts' icon,
  2. select the action from the lists (choose if you wish to do a Global shortcut, Shortcut Sequence, Application Shortcut or Command Shortcut),
  3. select the 'Custom' radio button at the bottom of the window,
  4. click on the button next to it (it may say 'None' or it may say what it is currently mapped to,
  5. press the key you wish to assign,
  6. click Apply.

Input Actions - DCOP

This is for those that wish to use keys such as volume up and volume down keys (via kmix in this example).

  1. Click on the 'Input Actions' icon,
  2. click the 'New Action' button at the bottom of the screen,
  3. click in the 'Action name' field in the top right and enter a name for your action,
  4. select what you wish to do from the drop down menu - I am setting a volume up key so select 'Keyboard Shortcut -> DCOP Call (simple)',

  5. click on the 'Keyboard Shortcut' tab at the top,
  6. click on the empty button,
  7. click on the empty button next to the X arrow,
  8. press the key you wish to use,
  9. go to a konsole and type 'dcop' followed by the name of the k application you wish to control. You will see a list, each item is referred to as an 'Object'. Choose the item you wish to use (in my case 'Mixer0'),
  10. enter the KDE application you wish to control,
  11. enter the object you wish to control (Mixer0 in my case),
  12. back on the konsole, type 'dcop appname objectName' eg: dcop kmix Mixer0 to discover the functions that can be called on that object.

  13. enter the function you wish to call into the 'Called function' box and any required arguments in the 'Arguments' box (in our case a 0 as there are no arguments),
  14. click 'Apply',
  15. try out your newly mapped item.

In the above steps you use the command line to discover information about 'dcop' commands. Instead of this, you can use a program called 'kdcop' - to launch this, click the 'Run KDCOP' button. Now you can investigate the dcop functions available to you. Note: you have to have the K application you wish to control via dcop open before it will appear in that listing.

Input Actions - Command/URL

  1. Click on the 'Input Actions' icon,
  2. click on the 'New Action' button,
  3. change the name of the action in the top right,
  4. select 'Keyboard Shortcut -> Command/URL (simple) from the dropdown list,

  5. click on the 'Keyboard Shortcut' tab at the top,
  6. click on the empty button,
  7. click on the empty button next to the X arrow,
  8. press the key you wish to use,
  9. click on the 'Command/URL Settings' tab,
  10. enter the command/url you wish to launch,
  11. click 'Apply'.

You should now have a set of working keys, doing what you want.