Вариант 1
источникMost modern keyboards are equipped with a number of multimedia keys. This article explains what needs to be done in order to use those keys.
Whenever a key is pressed on the keyboard, the kernel generates a raw scancode, which can be mapped to a keycode. X does this slightly differently and reads the kernel keycode table at startup, then maps the keycode to its own keycode table. Each keycode can be mapped to a keysym, which is a string that represents a key.
There are several applications that show the keycodes.
Install the xev program:
And run it in an X terminal.
Pressing keys on the keyboard will cause their keycodes and other information to printed in the xev window. The keycodes relating to individual keys can be discovered in this way. The output of xev will look similar to this:
Code: Output of xev |
KeyRelease event, serial 31, synthetic NO, window 0x2800001, root 0x7d, subw 0x0, time 2792224, (-22,86), root:(565,101), state 0x10, keycode 160, same_screen YES, XLookupString gives 0 bytes: |
The "keycode" value is what is relevant. In this example it is "160." Make note of each keycode value in respect to each extended key.
The following script can help find the keycodes in the output of xev:
Run this instead of plain xev. Press all multimedia keys in order, then close the xev window. The filtered output appears only after closing the window, for example:
Code: Output of xev after closing window |
keycode 36 = keycode 144 = keycode 162 = keycode 164 = |
Most likely, as in this example, the first line in the output does NOT correspond to a multimedia key (it is the keycode value for the Enter key).
A single key can be identified without ending xev by:
If pressing each key produces output from xev then jump ahead to Setting up xmodmap. If pressing a key doesn't do anything at all (i.e., xev produces no output), the raw scan code will need to be found.
You can also switch to console and run
to see the scan codes, or
to see the key codes.
KeyTouch provides an all-in-one solution for multimedia keyboards.
Start it under X and select the keyboard you have. After that, you can use it to connect functions or programs to your special keys. You should not need an xmodmap.
If your keyboard is not in the list, emerge keytouch-editor (which is masked by keyword at the time of this writing).
The official manual is available at http://keytouch.sourceforge.net/. Basically you just hit each key and assign a name. Don't forget to send the file to the keytouch project (you will be asked for that when saving the file) to help others. The manual can help you solve problems such as the following error from dmesg:
keyboard.c: can't emulate rawmode for keycode XXX
Another simple way to bring your multimedia keys to life is to use "lineakd". LinEAK is available via portage (see http://lineak.sourceforge.net for details).
If you like to control more than one application you will need a command wrapper like ReMoot. ReMoot can control audacious, Rhythmbox, Amarok, Quod Libet, xine, kaffeine and some more. The command 'remoot play' will control the active application multimedia application and therefore you don't have to asign one key to one application. This is very useful together with LinEAK or Keytouch
If the above methods didn't recognise your keys and your keyboard is connected via the PS/2 connector (not USB), run the following command in an X terminal:
atkbd.c: Unknown key released (translated set 2, code 0x96 on isa0060/serio0). atkbd.c: Use 'setkeycodes e016 <keycode>' to make it known.
This means that the kernel doesn't have keycodes mapped to your keyboard's scancodes.
You will have to add one line in /etc/conf.d/local.start for each missing key as follows:
... setkeycodes e008 136 setkeycodes e016 150 ....
Where the first number (e008) is the raw scan code (what you see in dmesg, or get from getkeycodes) and the second number (136) is an unused keycode in your kernel. In general you can find a good keycode by taking the last 2 digits of this first number, converting it from hex (base-16) to decimal (base-10) and adding 128.
Here is a simple bash script that can do the conversion for you. Just press all of your multimedia keys and run this script afterwards. It will parse the output of dmesg for unknown keys and give you the lines you should add to /etc/conf.d/local.start.
This will set up the proper scancode - keycode mapping every boot. To set them up without rebooting, run the following as root:
After you have the proper mappings set up, restart X and try running xev again to ensure that a keycode is displayed for each multimedia key you want to use.
atkbd.c is not used for USB keyboards, and if your kernel is configured to use full HID support you will not see any kernel messages. Instead you will need to run a user-mode program called getscancodes to read the key codes from one of the /dev/input/eventX devices, as described here.
For example by this method it is possible to find out that the codes for the zoom slider on a Microsoft Natural Ergonomic Keyboard 4000 are 0x1a2 and 0x1a3. Check the Microsoft Natural Ergonomic Keyboard 4000 article for more details.
Once all the multimedia keys are being recognised by xev, they need to be mapped to keysyms. Create a file called .Xmodmap in your $HOME directory.
! This works with Trust Silverline Direct Access keyboard ! The second stanza works for Dell Inspiron e1405 and e1505 laptops, as well as other ! standard keyboards (including the Logitech G15, and the Dell sk-8135 keyboard.) ! Use ! for comments keycode 222 = XF86PowerOff keycode 223 = XF86Sleep keycode 236 = XF86Mail keycode 229 = XF86Search keycode 230 = XF86Favorites keycode 178 = XF86WWW keycode 162 = XF86AudioPlay keycode 164 = XF86AudioStop keycode 160 = XF86AudioMute keycode 144 = XF86AudioPrev keycode 153 = XF86AudioNext keycode 176 = XF86AudioRaiseVolume keycode 174 = XF86AudioLowerVolume
A list of possible keysyms can be found in /usr/share/X11/XKeysymDB (!this file does not exist anymore). The following is a list of the more commonly used keysyms as found in XKeysymDB.
XF86ModeLock :1008FF01 XF86Standby :1008FF10 XF86AudioLowerVolume :1008FF11 XF86AudioMute :1008FF12 XF86AudioRaiseVolume :1008FF13 XF86AudioPlay :1008FF14 XF86AudioStop :1008FF15 XF86AudioPrev :1008FF16 XF86AudioNext :1008FF17 ... XF86HomePage :1008FF18 XF86Mail :1008FF19 XF86Start :1008FF1A XF86SplitScreen :1008FF7D XF86Support :1008FF7E XF86Away :1008FF8D XF86Messenger :1008FF8E XF86WebCam :1008FF8F XF86MailForward :1008FF90 XF86Pictures :1008FF91 XF86Music :1008FF92
All you have to do now is to call xmodmap whenever your X session starts, if this doesn't already happen automatically (it should.) Usually a good place to do this is your $HOME/.xsession file.
/usr/bin/xmodmap $HOME/.Xmodmap
Alternatively, you can set this up in ~/.xinitrc this way:
exec /usr/bin/xmodmap ${HOME}/.Xmodmap &
Remember to substitute $HOME for the full path of your home directory.
GDM setup If you are using GDM you can use the file /etc/X11/Xmodmap as a system wide Xmodmap. You can also change the location to another Xmodmap file if you wish. Simply change sysmodmap=/etc/X11/Xmodmap in the file /etc/X11/gdm/Init/Default to whatever you would like.
KDM setup Under KDM and KDE, the proper place to load ~/.Xmodmap file is ~/.kde/share/config/kdm/Xsession.
#!/bin/sh if [ -f $HOME/.Xmodmap ]; then /usr/bin/xmodmap $HOME/.Xmodmap fi
Do not forget to run "chmod +x ~/.kde/share/config/kdm/Xsession"
xfce4 setup If you are using xfce4-sessions, then you just need to place the .Xmodmap file to ${HOME}/.Xmodmap.
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 (see above for the best place to put the commands, here ~/.xinitrc is being used.)
# 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 above # Use "r" instead of "-r" to enable autorepeat instead if # the keyboard doesn't natively repeat the key.
Now that your multimedia keys have a keysym mapping, you can bind them to whatever function you want or your window manager allows you to. Note that some programs natively support hotkeys (especially media players) so it is more efficient (and lower latency) to use this mechanism where possible, as it doesn't rely on some other program executing a command to perform the action (see below for a list of known programs with built in hotkey support.)
These programs support hotkeys without window manager help, so they're much more responsive as a command doesn't have to be launched every time a key is pressed.
Since Audacious version 1.4 the hotkey plugin is available in the package audacious-plugins. To use the plugin go to the Audacious preferences, under Plugins, General, enable the Global Hotkey plugin and configure it by selecting the different commands and pressing the appropriate key.
If your window manager doesn't have a facility for keyboard shortcuts, or indeed if you want to switch between multiple window managers/desktop environments and keep the same keyboard shortcuts throughout, then xbindkeys may be the solution for you.
To install, a simple:
After installation you must edit the config file ~/.xbindkeysrc. If you don't have the file (you won't), you'll get it by running xbindkeys and reading). The file is well commented with examples. To use the key XF86WWW to open your webbrowser (Firefox in this case), place the following code snippet into the config file:
"firefox" XF86WWW #General format being: #"command to execute" # key combination
To use multemedia keys to control sound vulome, place the following code snippet into the config file:
"amixer -q set Master 2- unmute" XF86AudioLowerVolume "amixer -q set Master 2+ unmute" XF86AudioRaiseVolume "amixer -q set Master toggle" XF86AudioMute
You can use various modifiers (alt, shift, ctrl) to add additional shortcuts. For example, to launch a urxvt terminal with the key combination Ctrl-n, place the following code snippet in your config file:
"urxvt" Control + n
If you are running xbindkeys as a daemon and edit .xbindkeysrc, it will automatically update bindings so you won't have to restart it.
You will need to emerge bbkeys. Once bbkeys is installed, make sure bbkeys is ran whenever you start X. Example xinitrc:
bbkeys & exec blackbox
Now you will need to configure bbkeys. You can either use the global configuration file (usually /usr/share/bbkeys/bbkeysrc) or copy it to ~/.bbkeysrc and edit that instead. Example:
[begin] (bbkeys configuration file) # * CUT DEFAULTS * [keybindings] (begin keybindings) # * CUT DEFAULTS * [Execute] (XF86Mail) {thunderbird} [Execute] (XF86AudioPlay) {xmms --play-pause} [Execute] (XF86AudioStop) {xmms --stop} [Execute] (XF86AudioNext) {xmms --fwd} [Execute] (XF86AudioPrev) {xmms --rew} [Execute] (XF86AudioLowerVolume) {amixer -q set PCM 2- unmute} [Execute] (XF86AudioRaiseVolume) {amixer -q set PCM 2+ unmute} [end] (end keybindings) [end] (end bbkeys configuration)
That's all there is to it.
Open up your ~/.fluxbox/keys with your favourite editor. To control the basic XMMS functionality you append this example to your file:
None XF86AudioPlay :ExecCommand /usr/bin/xmms --play-pause None XF86AudioStop :ExecCommand /usr/bin/xmms --stop None XF86AudioPrev :ExecCommand /usr/bin/xmms --rew None XF86AudioNext :ExecCommand /usr/bin/xmms --fwd None XF86AudioLowerVolume :ExecCommand amixer -q set PCM 5%- unmute None XF86AudioMute :ExecCommand amixer -q set Master toggle None XF86AudioRaiseVolume :ExecCommand amixer -q set PCM 5%+ unmute
For certain cards it might work if you put PCM for mute instead of Master. It might give the desired effect (Volume Up button when pressed will unmute the card):
None XF86AudioMute :ExecCommand amixer -q set PCM toggle
Open your ~/.config/openbox/rc.xml file, search for section "keyboard" and, following the examples, add in the end of session:
<source lang=xml> <keybind key="XF86AudioPlay"> <action name="Execute"><execute>/usr/bin/xmms --play-pause</execute></action> </keybind> <keybind key="XF86AudioStop"> <action name="Execute"><execute>/usr/bin/xmms --stop</execute></action> </keybind> </source>
For more information refer to the documentation for openbox about actions and keybindings in http://icculus.org/openbox/index.php/Help:Contents#Configuration.
Just edit the file ~/.icewm/keys
key “XF86AudioLowerVolume” amixer sset PCM 5- key “XF86AudioRaiseVolume” amixer sset PCM 5+ key “XF86AudioMute” amixer sset Master toggle key “XF86AudioPlay” mpc toggle key “XF86AudioStop” mpc stop key “XF86AudioPrev” mpc prev key “XF86AudioNext” mpc next key “XF86WWW” firefox key “XF86Mail” firefox “gmail.com”
And restart IceWM.
Go to Settings > Keyboard Settings, and select the "Shortcuts" tab. To define our own key bindings, we have to create a new theme. Click "Add" to create it (note that all key bindings from the default theme are copied into the new theme). In the "Command Shortcuts" section, doubleclick on an empty slot, enter the command you would like to bind and press the according key. The keysym from your .Xmodmap should appear next to the command if everything works as expected. Done.
With KDE you can set almost all settings through the Control Center if you have a supported keyboard. Go to Control Center -> Regional & Accessibility -> Keyboard Layout and choose your Keyboard model. In Mandriva 2009, go to Configure Desktop -> Regional & Language -> Keyboard Layout and choose Keyboard model.
If Keyboard Layout is missing:
After you have set your model, use KHotKeys to map the keys to actions. You can also use simple DCOP calls to talk to Amarok.
If your keyboard is not supported you can try the following:
If you use kdm as your login manager, kdm will source the file ~/.xprofile on each login.
Simply create the file ~/.Xmodmap as mentioned above, then have a line in ~/.xprofile that has xmodmap use it.
/usr/bin/xmodmap $HOME/.Xmodmap
If this does not work, simply create a file ~/.kde/Autostart/xmodmap containing
#!/bin/sh /usr/bin/xmodmap $HOME/.Xmodmap
and make it executable.
Gnome-2.10: Go to Desktop > Preferences > Keyboard Shortcuts, or run gnome-keyboard-bindings, whichever suits your fancy. Make sure the Sound category in the Actions column is expanded, then click on the desired action. The entry in the Shortcut column will change to "New accelerator...." Press the desired key for the binding, and the shortcut is made. A proper entry should look similar to
Action | Shortcut |
Volume mute | XF86AudioMute |
If you feel more comfortable with (or are just that more adventurous), open up Gnome's Configuration Editor, either through the menus, or through the command gconf-editor, then navigate to Apps > gnome_settings_daemon > keybindings. For the even-more-adventurous, use your favorite editor, and open ~/.gconf/apps/gnome_settings_daemon/keybindings/%gconf.xml
A decent set to work with is:
<?xml version="1.0"?> <gconf> <entry name="www" mtime="1115511556" type="string"> <stringvalue>XF86HomePage</stringvalue> </entry> <entry name="email" mtime="1115511554" type="string"> <stringvalue>XF86Mail</stringvalue> </entry> <entry name="next" mtime="1115511504" type="string"> <stringvalue>XF86AudioNext</stringvalue> </entry> <entry name="previous" mtime="1115511503" type="string"> <stringvalue>XF86AudioPrev</stringvalue> </entry> <entry name="stop" mtime="1115511498" type="string"> <stringvalue>XF86AudioStop</stringvalue> </entry> <entry name="play" mtime="1115511489" type="string"> <stringvalue>XF86AudioPlay</stringvalue> </entry> <entry name="volume_up" mtime="1116696662" type="string"> <stringvalue>XF86AudioRaiseVolume</stringvalue> </entry> <entry name="volume_down" mtime="1115511485" type="string"> <stringvalue>XF86AudioLowerVolume</stringvalue> </entry> <entry name="volume_mute" mtime="1116697540" type="string"> <stringvalue>XF86AudioMute</stringvalue> </entry> </gconf>
Adding shortcuts to Window Maker is simple using the Window Maker Preferences Utility: WPrefs. By default WPrefs is the third icon down in the dock. If WPrefs is no longer in the dock, you can access it on most distros by running the following command in an X terminal:
You can go to the keyboard section of WPrefs to bind the extended keys to some predefined internal Window Maker commands.
Simply scroll right until the keyboard icon is visible and click on it.
You will see a list of internal commands that you can higlight. Select the command you want to bind and then click the "capture" button. Now simply hit the key and any modifiers (ctrl, alt, shift etc.) you want to bind to this function.
While binding internal Window Maker commands is useful, you can also bind external commands to keystrokes. The only way to do this is to add them to the main Window Maker menu, the same menu you can access from right clicking on the root window or hitting F12 by default.
In WPrefs you can click on the menu icon: the one next to the keyboard icon to access the menu.
An editable version of the menu will pop up outside of the main WPref window. You can drag any of the sample elements from the main WPrefs window to the editable menu to create a new element of that type.
Double-click on an element in the editable menu to change its name. Be sure to press Enter after completing the name change or else it will revert.
Adding a shortcut to a program entry will result in the shortcut keysym showing up in the menu; It will not show up in the editable version of the menu. Because the keysyms are a bit ugly you can tidy up the menu by sticking the programs in a submenu.
You can add a shortcut to a "Run Program" element by selecting it in the dummy menu and clicking the "Capture" button then pressing the key/keystroke you want to bind to that program.
Emerge the e16keyedit package. Then run 'e16keyedit' inside of enlightenment. Create a new keybinding, and press the 'Change' button to record a keystroke. Just press your new multimedia key and bind it to whatever action you'd like (use the 'Run' action to bind it to a command like aumix). Remember to press the 'Save' button when you're done.
Copy /etc/X11/ion3/cfg_bindings.lua to ~/.ion3/cfg_bindings.lua (if you did not do this already) and edit it. By using kpress(KEY, ACTION) you can bind actions to multimedia keys:
bdoc("Mute/Unmute Sound."), kpress("AnyModifier+XF86AudioMute", "ioncore.exec_on(_, 'amixer sset Master toggle')"), bdoc("Increase Volume."), kpress("AnyModifier+XF86AudioRaiseVolume", "ioncore.exec_on(_, 'amixer sset Master 3%+')"), bdoc("Decrease Volume."), kpress("AnyModifier+XF86AudioLowerVolume", "ioncore.exec_on(_, 'amixer sset Master 3%-')"), ....
Note that in some later versions of ion3, key bindings have moved from cfg_bindings.lua to cfg_ioncore.lua. Same syntax, just a different file. If you don't have an /etc/X11/ion3/cfg_bindings.lua to copy, this is probably why.
Add a binding in your configuration. FVWM-Crystal users can find a description of the modifiers used by Crystal in /usr/share/fvwm-crystal/fvwm/components/functions/Keyboard-Modifiers
For a system wide configuration using the Aumix mixer, modify the file /usr/share/fvwm-crystal/fvwm/components/functions/Mixer-aumix, otherwise copy it in ~/.fvwm-crystal/components/functions and add:
... Key XF86AudioLowerVolume A $[Mod0] Mixer-Volume-Down Key XF86AudioRaiseVolume A $[Mod0] Mixer-Volume-Up ....
Another example with FVWM functions, parameters, external command and key modifiers:
... # Same key with modifiers and call to an external program Key XF86AudioMute A $[Mod0] Exec exec alsaplayer --volume 0 key XF86AudioMute A C Exec exec alsaplayer --volume 1 ... # Another key with modifiers # + FVWM function key XF86AudioPlay A $[Mod0] Music-PlayPause key XF86AudioPlay A C Music-Pause # + FVWM function with parameter key XF86AudioPlay A $[Mod1] Music-Speed normal ....
An example with amixer:
key XF86AudioLowerVolume A A Exec exec amixer set Front 10%- key XF86AudioRaiseVolume A A Exec exec amixer set Front 10%+ key XF86AudioMute A A Exec exec amixer set Front toggle
FVWM-Crystal is using $[Mod0] which is not defined in plain FVWM. To determine the modifiers into FVWM, you can use the output of
xmodmap -pm
As $[Mod0] is defined as N (none) in Crystal and $[Mod1] as M for Meta (Alt), all that is needed is to replace all the occurrences of $[Mod0] by N and $[Mod1] by M:
Key XF86AudioLowerVolume A N Mixer-Volume-Down Key XF86AudioRaiseVolume A N Mixer-Volume-Up key XF86AudioPlay A N Music-Play key XF86AudioPlay A C Music-Pause key XF86AudioPlay A M Music-PlayPause
The program Magmakeys can be used tie arbitrary commands to specific hotkeys independently from the user logged in or the window manager used. This is especially useful for keys directly related to the hardware (e.g. volume control, enabling wireless network devices etc.). The Magmakeys daemon hooks into the input subsystem of the kernel and intercepts key presses on a system-wide basis; commands are then globally defined in /etc/magmakeys.conf:
# volume control KEY_VOLUMEUP 1 /usr/bin/amixer set Master 2%+ KEY_VOLUMEDOWN 1 /usr/bin/amixer set Master 2%- # keep changing the volume when holding the key KEY_VOLUMEUP 2 /usr/bin/amixer set Master 2%+ KEY_VOLUMEDOWN 2 /usr/bin/amixer set Master 2%- KEY_MUTE 1 /usr/bin/amixer set Master toggle
If you own an eMachines m68xx notebook and want to jump right to using the keys, you can use the following to setup the keys.
NB: These were created on an m6809, but I assume they're the same for the other m68xx models, if you have access to one of the other models and can confirm/deny this, please update this page.
First, we update the the keysyms. On an x86_64 system the file we want is /usr/lib64/X11/xkb/symbols/inet. Insert the following code:
// eMachines partial alphanumeric_keys xkb_symbols "emachines" { name[Group1]= "Laptop/notebook eMachines m68xx"; key <I2E> { [ XF86AudioLowerVolume ] }; key <I6D> { [ XF86AudioMedia ] }; key <I30> { [ XF86AudioRaiseVolume ] }; key <I20> { [ XF86AudioMute ] }; key <I6C> { [ XF86Mail ] }; key <I32> { [ XF86iTouch ] }; key <I65> { [ XF86Search ] }; key <I5F> { [ XF86Sleep ] }; key <I22> { [ XF86AudioPlay, XF86AudioPause ] }; key <I24> { [ XF86AudioStop ] }; key <I10> { [ XF86AudioPrev ] }; key <I19> { [ XF86AudioNext ] }; key <KP0> { [ KP_0 ] }; key <KP1> { [ KP_1 ] }; key <KP2> { [ KP_2 ] }; key <KP3> { [ KP_3 ] }; key <KP4> { [ KP_4 ] }; key <KP5> { [ KP_5 ] }; key <KP6> { [ KP_6 ] }; key <KP7> { [ KP_7 ] }; key <KP8> { [ KP_8 ] }; key <KP9> { [ KP_9 ] }; key <KPDL> { [ KP_Decimal ] }; key <KPAD> { [ KP_Add ] }; key <KPSU> { [ KP_Subtract ] }; key <KPMU> { [ KP_Multiply ] }; key <KPDV> { [ KP_Divide ] }; };
Now, we add the required references to this keyboard layout to X11/kxb/rules/(xorg
In the X.Org file we add it to the list of $inetkbds like so:
In xorg.lst we add one line among the large list of models.
... emachines Laptop/notebook eMachines m68xx ....
And finally in xorg.xml we give it a description, which can be localized.
<source lang=xml> ... <model> <configItem> <name>emachines</name> <description>Laptop/notebook eMachines m68xx</description> </configItem> </model> ... </source>
Now, after all that, restart your X server and there's a fresh new m68xx keyboard waiting to be selected. In KDE this can be selected easily by opening the Keyboard Layout Control Module and choosing the newly added "Laptop/notebook eMachines m68xx" from the Keyboard Model list. Any of the specials keys can then be bound as shortcuts the way you configure any other shortcut.
Since this is at the X server level, and system wide, it should be accessible to all users in any window manager.
X11 only supports key codes up to 255. It is an inherent limitation and they say that the one of the easiest ways to fix it would be to switch to protocol version X12. So, don't hold your breath.
More and more keyboards (and remotes) generate key codes larger than 255. If some keys of your keyboard or a remote control do now show up in X, and xev does not show anything for them, try showkeys. If it will show key codes larger than 255 - read on.
There are different solutions to this problem. The easiest one is to remap the keys to fit into 0..255 range. For AT keyboards use showkeys -s or getkeycodes and then setkeycodes as explained above. For USB keyboards (and for AT keyboards too) you need to emerge udev with the keymap USE flag. Then, as explained in the README.keymap.txt run
where X is a number of your device. Try different numbers, if you don't see multimedia key presses from your keyboard - some keyboards report normal keys and multimedia keys on different event devices.
Once you've figured out the device, and a key to remap, find in /usr/include/linux/input.h an appropriate KEY_XXXXX constant with a code less than 255. You can try to remap the key right away, for example:
This command has an immediate effect, all running programs will see new key code without restarting.
To make your changes permanent, create a mapping file, and put it in /lib/udev/keymaps/. Name it after a model of your keyboard or remote. Such a file may look simialr to
0xFFBC0025 open # former tv 0xC008D search # former program
And add an appropriate rule to /etc/udev/rules.d/ (README.keymap.txt suggests to add it to /lib/udev/rules.d/95-keymap.rules but I prefer to keep all settings and modifications in /etc). Your udev rule might look like
SUBSYSTEM=="input", ACTION=="add", KERNEL=="event*", SUBSYSTEMS=="usb", ENV{ID_VENDOR_ID}=="046e", ENV{ID_MODEL_ID}=="5577", RUN+="keymap $name msi-wireless-keyboard"
That's all!
Alternatives:
Many applications have methods to control them from command line. These are perfect for creating shortcuts to use with multimedia keys.
If you like to control all the apps below (and 20+ more apps) you will need a command wrapper like ReMoot. ReMoot can control xmms, Mplayer, Rhythmbox, Amarok, Quod Libet, xine, kaffeine and 20 more apps. The command 'remoote play' will control the active multimedia application and therefor you don't have to asign one key to one application. ReMoot works best with [/HOWTO_Use_Multimedia_Keys#Alternative:_lineakd_or_keyTouch Lineak], Keytouch or xbindkeys and has a web-frontend that works remote control with a PDA or any web enabled gadget.
Audacious has some straightforward command line switches. You can see more by executing this command in a terminal:
Code: Audacious command line switches from the audacious manpage |
audacious --rew # Skip backwards in playlist. audacious --stop # Stop current song. audacious --play-pause # Pause if playing, play otherwise. audacious --fwd # Skip forward in playlist. |
Rhythmbox can be controlled using dbus.
Code: Dbus commands |
dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.rhythmbox /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next # Next track dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.rhythmbox /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous # Previous track dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.rhythmbox /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause # Play/Pause dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.rhythmbox /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Stop # Stop |
This is not an exhaustive list of commands.
It can also be controlled using rhythmbox-client.
Code: rhythmbox-client commands |
rhythmbox-client --next # Next track rhythmbox-client --previous # Previous track rhythmbox-client --play-pause # Play/Pause |
For all options, type rhythmbox-client --help or man rhythmbox-client
Code: amarok command line switches from "dcop amarok player" (v. 1.4.4) |
QCStringList interfaces() QCStringList functions() QString version() bool dynamicModeStatus() bool equalizerEnabled() bool osdEnabled() bool isPlaying() bool randomModeStatus() bool repeatPlaylistStatus() bool repeatTrackStatus() int getVolume() int sampleRate() int score() int rating() int status() int trackCurrentTime() int trackCurrentTimeMs() int trackPlayCounter() int trackTotalTime() QString album() QString artist() QString bitrate() QString comment() QString coverImage() QString currentTime() QString encodedURL() QString engine() QString genre() QString lyrics() QString lyricsByPath(QString path) QString lastfmStation() QString nowPlaying() QString path() QString setContextStyle(QString) QString title() QString totalTime() QString track() QString type() QString year() void configEqualizer() void enableOSD(bool enable) void enableRandomMode(bool enable) void enableRepeatPlaylist(bool enable) void enableRepeatTrack(bool enable) void mediaDeviceMount() void mediaDeviceUmount() void mute() void next() void pause() void play() void playPause() void prev() void queueForTransfer(KURL url) void seek(int s) void seekRelative(int s) void setEqualizer(int,int,int,int,int,int,int,int,int,int,int) void setEqualizerEnabled(bool active) void setEqualizerPreset(QString name) void setLyricsByPath(QString url,QString lyrics) void setBpm(float bpm) void setBpmByPath(QString url,float bpm) void setScore(int score) void setScoreByPath(QString url,int score) void setRating(int rating) void setRatingByPath(QString url,int rating) void setVolume(int volume) void setVolumeRelative(int ticks) void showBrowser(QString browser) void showOSD() void stop() void transferDeviceFiles() void volumeDown() void volumeUp() void transferCliArgs(QStringList args) |
Code: Quod Libet command line switches from "quodlibet --help" |
quodlibet --previous # Skip backwards in playlist quodlibet --play # Start playing current playlist quodlibet --play-pause # Play if stopped, pause if playing quodlibet --pause # Pause playback quodlibet --next # Skip forwards in playlis |
If you use MPD your client may already support some keysyms. For instance gmpc correctly recognises XF86AudioNext, XF86AudioPrev, XF86AudioStop, and XF86AudioPlay. Furthermore, gmpc works with profiles, and whichever you have selected will be played, paused, stopped, next'd, or previous'd autimagically.
If you do not use gmpc, or do not want to leave gmpc running then you may want to bind these keys to short cuts to the command line MPD client, mpc. first you must install mpc by executing:
The mpc command line switches are:
Code: mpc switches from "mpc --help" |
mpc next # Play the next song in the current playlist mpc prev # Play the previous song in the current playlist mpc toggle # Toggles Play/Pause, plays if stopped mpc stop # Stop the currently playing playlists |
ALSA can be controlled using amixer. The following commands will adjust the PCM levels of your ALSA soundcard.
Code: Controling PCM levels with amixer |
amixer sset PCM 2+ # This will increase the PCM hardware volume value by 2 amixer sset PCM 2- # This will decrease the PCM hardware volume value by 2 amixer sset PCM toggle # This will toggle the PCM between muted and unmuted states |
Not all sound cards support mute toggling. The following script can be used on such cards. It saves the current volume to $HOME/.lastVolume and sets it to 0. To "unmute", execute the script again and the previous value will be restored.
#!/bin/bash # simple script to mute by changing volume filename="$HOME/.lastVolume" numid="30" #find apropriate number with: amixer controls volume=$(amixer cget numid=$numid | grep : | sed -e 's/ : values=//') if [ $volume = '0' ] # Or if that doesn't work try: if [ $volume = '0,0' ] then echo "Volume is 0, restoring" volume=$(cat $filename) amixer -q cset numid=$numid $volume &> /dev/null else echo "Volume is $volume, muting" echo $volume > $filename amixer -q cset numid=$numid 0 &> /dev/null fi
(Verified with amixer 1.0.13)
Code: Banshee command line switches from "banshee --help" |
Usage: banshee [ options ... ] where options include: ... --show Show window --hide Hide window --next Play next song --previous Play previous song --toggle-playing Toggle playing of current song --play Play current song --pause Pause current song --shutdown Shutdown Banshee ... |
As of v0.7.4, Goggles Music Manager supports the following command line options:
Code: Goggles Music Manager command line options from "gmm --help" |
gmm --play Start playback gmm --play-pause Play if stopped, pause if playing gmm --pause Pause playback gmm --previous Play previous track gmm --next Play next track gmm --stop Stop playback |
To get switching on/off the illumination of multimedia keyboard to work under X using key Scroll_Lock:
Change mapping of Scroll_lock by extending ~.Xmodmap with something like this:
keycode 78 = XF86LightBulb
Of course you could use any other key you like.
Make a little script somewere like this:
Code: kbd-illum |
#!/bin/bash # # /usr/local/bin/kbd-illum - control illumination of keyboard # case "$1" in ( on ) xset led 3 ;; ( off ) xset -led 3 ;; ( -t | --toggle ) xsetleds -show | grep -q 'ScrollLock \+on' && xset -led 3 || xset led 3 ;; ( -s | --status ) xsetleds -show | grep -q 'ScrollLock \+on' && echo on || echo off ;; ( * ) echo "usage: $( basename "$0" ) -t|--toggle | -s|--status | on | off" esac |
and make it executable.
Of course you need xsetleds installed:
Then bind key XF86LightBulb to this command:
/usr/local/bin/kbd-illum --toggle
like explained above and you are done.