Extra Keyboard Keys

From ArchWiki

Jump to: navigation, search


Contents

[edit] See if your kernel can see the scancode

The first thing you should do is to see if the key produces a scancode 1 as that will mean you won't need to bother with working or non-working third-party apps. To see if the kernel recognizes the extra key, press the non-standard key(doesn't matter wether you are in xorg or framebuffer or whatever) and see if a msg similar to:

atkbd.c: Unknown key pressed (translated set 2, code 0x9e on isa0060/serio0).
atkbd.c: Use 'setkeycodes e01e <keycode>' to make it known.

appears at the bottom after typing:

dmesg

If it does then all you have to do is to find a spare keycode(as root):

getkeycodes

and bind the scancode to the free keycode:

setkeycodes e01e 129

for example. I think X recognizes scancodes up to 229(atleast that's the highest number gnome's keymapping utility wants to work with for me...)

You can see if xorg now recognizes the key by launching 'xev' and watching for output when you press the key.

All keyboard program launching programs will recognize the key and will allow you to bind the key to do some action. Programs like 'xbindkeys' or gnome's in the entry below here...

To keep the key over reboots you have to put the cmd's in some startup file like rc.local(all users) or .bashrc(user specific).

setkeycodes 0x71 112 &

More enlightening info can be found on these pages: HAL Keymap Quirks There are also another arch wikipage here: Hotkeys but i don't think there is a point to trying showkey as it didn't work for me and the HAL guide only mentions the dmesg output.

[edit] In Gnome

Users of the Gnome Desktop Environment may find their extra keys are recognised by Gnome's keybindings tool. This is part of the Control-Center package, and can be accessed via System->Preferences->Keyboard Shortcuts, or by running gnome-keybinding-properties. Gnome has a handy on-screen display of volume levels if your multimedia keys are configured this way. However, many extra keys will not be configurable in this manner.

[edit] In KDE

Method 1

Info extracted from: KMiLo info page

(C&P) In the KDE CVS version there is also a generic plugin for all kayboards with volume up/down keys acknowledged by X/KDE by default. Just start the X program xev and press your laptop's vol up/down keys to check. If it prints out some meaningful information, you can use it to setup KDE to take care of these and connect them to RaiseVolume, etc.

If it does not work out of the box, your X keybindings have to set up. Usually, you do this in ~/.Xmodmap

Example:

keycode 129 = XF86AudioMedia
keycode 144 = XF86AudioPrev
keycode 153 = XF86AudioNext
keycode 160 = XF86AudioMute
keycode 161 = XF86Calculator
keycode 162 = XF86AudioPause
keycode 164 = XF86AudioStop
keycode 174 = XF86AudioLowerVolume
keycode 176 = XF86AudioRaiseVolume
keycode 223 = XF86Standby

This assigns e.g. keycode 160 to XF86AudioMute which triggers mute in the kmilo generic plugin. How to find out? start xev, move your mouse into the window and press the keys. .Xmodmap is read every time you start X. Use "xmodmap .Xmodmap" to test your configuration file.

The available names for the keys ( e.g. XF86AudioMute ) can be found in the file /usr/share/X11/XKeysymDB


Method 2 - The practical way

As described above in konsole type xev to get the keycodes. Write them down. The create a file in /etc/X11/ named Xmodmap. I give as an example my Xmodmap file (you can have more or less and different keycodes and/or buttons to you keyboard):

keycode 176 = XF86AudioRaiseVolume
keycode 174 = XF86AudioLowerVolume
keycode 160 = XF86AudioMute
keycode 236 = XF86Mail
keycode 178 = XF86WWW
keycode 135 = XF86MyComputer
keycode 140 = XF86Launch1
keycode 248 = XF86Launch2
keycode 214 = XF86Launch3
keycode 146 = XF86AudioMedia
keycode 201 = XF86Launch4
keycode 222 = XF86PowerDown

Create a new bash script in /usr/local/bin/ named hotkeys.sh and paste the following:

#!/bin/bash
xmodmap /etc/X11/Xmodmap

Make it executable:

chmod +x /usr/local/bin/hotkeys.sh

Now you can make a shortcut and place it anywhere. I have made one in the kde menu and in ~/.kde/Autostart folder. In the kde menu editor you can bind these keys to any program you wish. Alternatively you can make manually a shortcut for /usr/local/bin/hotkeys.sh. In konsole type:

nano ~/.kde/Autostart/hotkeys.desktop

And paste the following:

[Desktop Entry]
Comment=
Exec='/usr/local/bin/hotkeys.sh'
GenericName=
Icon=keyboard
Name=hotkeys
Path=
StartupNotify=false
Terminal=0
TerminalOptions=
Type=Application
X-KDE-SubstituteUID=false
X-KDE-Username=

Now, if you want to bind a key with a program(for example: XF86WWW with Firefox), you can do it through the Control Center. Go to Control Center -> Regional & Accessibility -> Keyboard Shortcuts -> Command Shortcuts, choose the program and press the key.

[edit] HAL

HAL(or hal-info) is now supposed to replace the functionality of lineakd, keytouch and similar programs, so you might want to go that route for the future.

HAL information

[edit] The Keytouch Program

KeyTouch is a program which allows you to easily configure the extra function keys of your keyboard. This means that you can define, for every individual function key, what to do if it is pressed. The wiki will try to explain how keytouch is used in Arch linux. For further documentation, please have a look at the keytouch documentation at http://keytouch.sourceforge.net/doc.html

[edit] Install

  • Install keytouch package from the community repo:
# pacman -S keytouch

[edit] Alternative way (build it yourself)

  • Download the keytouch PKGBUILD from here. Don't forget the files 'keytouch.install', 'keytouch.daemon', and 'keytouch.desktop' as well - they are used by the PKGBUILD in the 'source' list, and may be accessible from the same url given. Put these 3 files and the PKGBUILD in the same directory.
  • Run makepkg
makepkg
  • Install Package Using Pacman
pacman -U keytouch-$VERSION.pkg.tar.gz

[edit] Make Keyboard File

Note: You need a keyboard file for your keyboard model. The package build includes some of them. You can also check http://keytouch.sourceforge.net/dl-keyboards.html

If your model is not included in the keytouch package you will need to create one for yourself:

  • Install keytouch-editor:
# pacman -S keytouch-editor
  • Make sure you have evdev loaded (you should not need to do this if you using the stock kernel)
# modprobe evdev
  • We are going to need to make a keyboard file which is very simple. You need to find out which input device is your keyboard first:
# ls /dev/input/

Every event device (like a keyboard or a mouse) is related to one of these files. To find out which file belongs to your keyboard, run:

# keytouch-editor /dev/input/eventX mykeyboardconfig

Replace the X by a number. KeyTouch editor will first show some information about the device, including its name (”Input device name”) that can tell you if you have chosen the correct event device. KeyTouch editor asks you to press one of the extra function keys. If the program continues after pressing the extra function key, you have chosen the right event device. If not terminate the program by pressing Ctrl+C and try another event device. Note that when your keyboard is connected via USB there are two event devices: /dev/input/eventA (where A is replaced by a number) for all ”normal” keys and /dev/input/eventB (where B = A+1) for the extra function keys.

  • After you have found the correct device, follow the steps. keytouch-editor asks your name and the name of the manufacturer and model of your keyboard.
  • Now it is time to tell keytouch-editor about your extra function keys. You will see the following message:
Press an extra function key or press enter to finish...

If your keyboard is connected via USB or you started keyTouch editor with the ”–acpi” option, you will not see this message, but instead:

Press return to a new key or enter F followed by return to finish...
  • First you will have to press the extra function key so that the program knows which key you mean. It is important that you do not press any other key than the extra function key. After pressing the key you will be asked to enter the keys name, keycode and default action.
  • Key name

Choose an appropriate name for the key. If there is for example a text label on the key, use the label as the key’s name.

  • Keycode

Use one of the keycodes listed below. It actually doesn’t matter which keycode you choose. However it is recommended that you choose a keycode that matches the best the function of the key. A keycode may only be used once in a keyboard file.

AGAIN               EJECTCLOSECD        MAIL              REFRESH
ALTERASE            EMAIL               MEDIA             REWIND
BACK                EXIT                MENU              RIGHTMETA
BASSBOOST           FASTFORWARD         MOVE              SCROLLDOWN
BOOKMARKS           FILE                MSDOS             SCROLLUP
BRIGHTNESSDOWN      FINANCE             MUTE              SEARCH
BRIGHTNESSUP        FIND                NEXTSONG          SENDFILE
CALC                FORWARD             OPEN              SETUP
CAMERA              FRONT               PASTE             SHOP
CANCEL              HANGUEL             PAUSE             SLEEP
CHAT                HANJA               PAUSECD           SOUND
CLOSE               HELP                PHONE             SPORT
CLOSECD             HOMEPAGE            PLAY              STOP
COFFEE              HP                  PLAYCD            STOPCD
COMPOSE             ISO                 PLAYPAUSE         SUSPEND
COMPUTER            KBDILLUMDOWN        POWER             SWITCHVIDEOMODE
CONFIG              KBDILLUMTOGGLE      PREVIOUSSONG      UNDO
CONNECT             KBDILLUMUP          PRINT             VOLUMEDOWN
COPY                KPCOMMA             PROG1             VOLUMEUP
CUT                 KPEQUAL             PROG2             WAKEUP
CYCLEWINDOWS        KPLEFTPAREN         PROG3             WWW
DELETEFILE          KPPLUSMINUS         PROG4             XFER
DIRECTION           KPRIGHTPAREN        PROPS             YEN
EDIT                LEFTMETA            QUESTION
EJECTCD             MACRO               RECORD

You can find the correct keycodes from here: http://keytouch.sourceforge.net/keytouch_editor/node7.html

  • Default action

It is important to realize that the default action for a key, is not the action you want to use for this key, but one that corresponds to the function of the key. The default action can be a program or a plugin. If it is a program, just fill in the name of the program. If it is a plugin type ”plugin” (without the quotes) instead. Then fill in the name of the plugin. To get a list of all available plugins, run keyTouch and go to the ”Preferences” part. Select the plugin and click the ”Information...” button to get a list of the functions of the selected plugin. After entering the plugins name in keytouch-editor, fill in the function name. Note that the name and function you fill in are case sensitive.

  • When you entered the information, the program asks again to press an extra function key. If there are no more extra function keys, just press enter to write the output file and terminate the program.

[edit] Share it

After you made the file and tested it, it would be a good idea to send it to the author of keytouch so he can include it in the next release. This helps future users of keytouch who have the same keyboard as you do.

marvinr users.sourceforge.net

(You know there's a missing @ because of spam bots ;))

[edit] Configure keytouch

  • We now need to run keytouch
keytouch
  • What to do...
  1. When you see the list of keyboards select import and find where you put the keyboard config file you just made.
  2. Now you should see your keyboard module and manufacturer. Select it and click ok.
  3. Now you get to the keytouch configuration theme. I think this is pretty self explanatory.

[edit] Starting the keytouch daemon

  • You should start the keytouch daemon at boot time (add keytouch to the daemons array in /etc/rc.conf)
  • You have to load keytouchd on your session startup. There is a script /etc/X11/Xsession which runs all daemons located in /etc/X11/Xsession.d/ including the keytouchd.
    • You can add /etc/X11/Xsession into your ~/.xinitrc if you log in from console
    • If you, however, use KDM as your login manager .xinitrc will not be parsed. You can add /etc/X11/Xsession to your session list of your Desktop Environment (Gnome, Kde, Xfce-svn, among others).

[edit] Troubleshooting

  • When I change the volume with the special keys, the OSD looks ugly. What's wrong?:

Maybe you have started the /etc/X11/Xsession script as root. This is what happens when you place "/etc/X11/Xsession" on a script like /opt/kde/share/config/kdm/Xstartup. The only thing that /etc/X11/Xsession script does, is to look on /etc/X11/Xsession.d/ and execute every script that is there. Once you have installed keytouch, two scripts are created there:

$ pwd
/etc/X11/Xsession.d
$ ls
91keytouch-acpid_launch  92keytouchd_launch

If them aren't executed, there is no keytouchd for you. But if you execute them as root (e.g. in a KDM startup script) they will look ugly and that isn't good for most people. Just run them as yourself (e.g. creating a symbolic link of /etc/X11/Xsession in ~/.kde/Autostart).

  • My multimedia keys (Play/Pause/Previos/Next...) doesn't work at all:

The problem is probably the same as above. If you run keytouchd as root, the programs you run with the multimedia keys are expected to run as root, they just won't work.

  • I've just created a brand new keyboard file for my own model (using keytouch-editor) but when I select it in keytouch, it says that my keyboard file doesn't exist. I know that is there!:

Actually, the error isn't that the file doesn't exist: It only has a bad filename. When you make your own keyboard file, you have to make sure that your filename has exactly this format:

Model.Manufacturer

For example:

Satellite-L25-SP141.Toshiba

That should do the trick.

[edit] The Lineak Program

http://lineak.sourceforge.net/

Have you ever wanted to get your multimedia keys to work under linux? If so; then Lineak is the perfect program for you because it does exactly this, Plus more (if needed). Lineak is a utility designed to enable the use and configuration of those special keys on Internet, Easy Access and Multimedia keyboards in Linux. It consists of three programs: lineakd: this is the daemon that listens for incoming key and mouse events. lineakconfig: this is the GTK+ GUI, which provides easier configuration Klineakconfig: this is the KDE GUI which allows you to define keyboards, and configuration mappings for easier configuration. If your keyboard is not directly supported by lineakd, klineakconfig provides an easy to use graphic interface to both getting your keyboard working, and submitting your keyboard for inclusion into lineakd.

Personally, In this tutorial I am not going to be using any of the GUI tools that I meantioned. I much rather do everything by hand, besides, you'll learn more this way. I will however provide more information on these tools at the end of this Wiki if you're interesting in GUI tools.

If you do have any problems with this howto, please e-mail me at. twiistedkaos@gmail.com. I'd much appreciate it, it'll help me enhance my howto writing skills :).

[edit] Check to see if Lineak supports your keyboard

Does Lineak support my keyboard? Heck if I know, does it? There is a very easy way to check though, and I'll tell you exactly how! Simply type this into your terminal shell:

   xev

You should get a window that pops up along with some terminal output. Now press one of your multimedia keys, any... It doesn't really matter at this point. You should get an output like the following:

   KeyPress event, serial 32, synthetic NO, window 0x2600001,
   root 0xea, subw 0x0, time 24644050, (143,-13), root: (548,770),
   state 0x0, keycode 223 (keysym 0x0, NoSymbol), same_screen YES,
   XLookupString gives 0 bytes:
   XmbLookupString gives 0 bytes:
   XFilterEvent returns: False
   KeyRelease event, serial 32, synthetic NO, window 0x2600001,
   root 0xea, subw 0x0, time 24644215, (143,-13), root: (548,770),
   state 0x0, keycode 223 (keysym 0x0, NoSymbol), same_screen YES,
   XLookupString gives 0 bytes:

If you get something around these lines, then your keyboard will be supported, if you don't get anything make sure the "Event Tester" window is the active one when you press the key and then try again. If you still don't get something like what I pasted above then sadly, your keyboard is one of the few that aren't supported and won't ever be supported through Lineak, even on Windows these rare keyboards require "special" drivers.

[edit] Software Installation

!!These instructions are out of date!! lineakd & lineak_defaultplugin are no longer in the repo's, please acquire and build them from AUR.

Open your terminal shell and type in the following:

   pacman -Sy lineakd lineak_defaultplugin

If you want OSD (On Screen Display) then you should also install this plugin:

   pacman -Sy lineak_xosdplugin

and when ever you press a key you'll get a nice little text displayed on your screen telling you what key you just pressed. But in my case I found this sort of annoying and skipped it :P.

[edit] Configuring Your Specific Keyboard

Lineak does support many keyboards so you may want to check and see if your keybaord is supported by Lineak. But, for educational purposes. I am going to explain to you how to write your own keyboard layout from scratch. So even if your keyboard is / or isn't supported this method will always work.

Once again run xev:

   xev

Make sure the "Event Tester" window is the active one and start pressing your multimedia keys one by one and write down somewhere what the keycode is. For example:

   KeyPress event, serial 32, synthetic NO, window 0x3a00001,
   root 0xea, subw 0x0, time 27586934, (-4,185), root: (0,253),
   state 0x0, keycode 234 (keysym 0x0, NoSymbol), same_screen YES,
   XLookupString gives 0 bytes:
   XmbLookupString gives 0 bytes:
   XFilterEvent returns: False

The keycode for that key is 234. So I would write down something like: GoBack - 234. Get it? Now do that for all your multimedia keys you plan to setup. Here's the list I have:

   GoBack	  = 234
   Play	     = 162
   Favorites	  = 230
   Mail             = 236
   SpeakerOff  = 160
   Home          = 178
   Next	    = 233
   Search        = 229
   Repeat        = 231
    Cancel         = 232
   ScreenShot	= 111

Now open up /etc/lineakkb.def in any editor you feel like. And create a section like this:

   [HP]
   brandname = "HP"
   modelname = "Custom"
       [KEYS]
                GoBack	= 234
                Play	= 162
                Favorites	= 230
                Mail        = 236
                SpeakerOff  = 160
                Home        = 178
                Next	= 233
                Search      = 229
                Repeat      = 231
                Cancel      = 232
                ScreenShot	= 111
       [END KEYS]
   [END HP]

Now you have your basic configuration done!! Cool huh? Now lets test and make sure that you have it configured correctly. Type this into your terminal shell:

   lineakd -c HP

then type:

   lineakd -v

Press each and every one of your keys and make sure they are outputing the correct settings. Then press Ctrl+C if everything is correct and move onto the next step.

Type in the following in your terminal shell

   mkdir ~/.lineak

then type:

   nano ~/.lineak/lineakd.conf

just replace nano with your favorite editor. In that file put something similar to the folllowing:

   Cancel = xmms --stop (or "remootstop" to make it work with most apps
   Favorites = firefox
   GoBack = xmms --rew 
   Next = xmms --fwd
   Home = nautilus --no-desktop /home/josh
   Mail = firefox http://www.gmail.com/
   Play = xmms --play-pause  
   Repeat = 
   Search = 
   Sleep = 
   SpeakerOff = 
   ScreenShot = sh $HOME/screen.sh

Save that file and now in your terminal type the following:

   lineakd &

and you will now have your multimedia keys setup correctly. Now just add the command lineakd & to your session startup and walla. You now have your very own multimedia keyboard working on linux.

[edit] ReMoot

ReMoot is not a key mapper but it is very handy to use with a key mapper like Lineak or Keytouch. Usually its only possible to map an action to ONE application. By mapping your multimedia keyboard to ReMoot you can control most (18) multimedia applications with the same keys (play/pause buttons etc.).

remoot is available in AUR.

[edit] Share it

After you have made your new /etc/lineakkb.def, please send it to the developers of lineak by emailing the file (or pasting it into the body of your email, this is usually preferred with mailing lists) to

lineak-devel lists.sourceforge.net

Again, the @ is missing for the benefit of spam bots. Sharing the file allows other users of lineak who have the same keyboard as you to benefit from your efforts in getting lineak to work.

[edit] Disabling auto-repeat

(Almost C&P from Gentoo Wiki)

You may find that your keyboard has autorepeat enabled for the multimedia keys, which has the undesirable effect of the "next track" button sometimes skipping ahead by too many songs or the "play/pause" button pausing and then resuming immediately, if you accidentally hold the button down for a fraction too long.

Rather than altering your whole keyboard's auto-repeat timing to fix this, you can disable auto-repeat completely for specific keys (or enable it, if you have buttons to control the volume and you'd like to be able to hold these down instead of pressing them repeatedly to adjust the volume.) This can be done by running the xset command at startup (a good place is /etc/X11/xinit/xinitrc):

# Disable autorepeat for multimedia keys (except the volume controls)
xset -r 162 -r 164 -r 160 -r 144 -r 153

# The keycodes are the same ones supplied to xmodmap, or detected by xev

# Use "r" instead of "-r" to enable autorepeat instead if
# the keyboard doesn't natively repeat the key.

[edit] GUI Tools

LineakConfig - http://prdownloads.sourceforge.net/lineak/lineakconfig-0.3.2.tar.gz - GTK+ GUI

klineakconfig - http://prdownloads.sourceforge.net/lineak/klineakconfig-0.5.1.tar.gz - QT / KDE GUI

These are pretty straight forward GUI tools and you should have no problem in using these tools.

[edit] External Links

Multimedia Keys in Gentoo Wiki (very complete and useful)

Personal tools