Multimedia Key Mapping in Mythbuntu
Multimedia Keys are also known as Hot keys, Hotkeys, and Media keys. It is useful to map or remap the media keys or defaults assigned by Mythbuntu for buttons on a multimedia keyboard or RF mini-keyboard remote for things like Play/Pause, Stop, Back, Forward, Mute, Vol Up and Vol Down to name a few examples.
There are different ways to accomplish this, both involve the same end process. It is the initial setup and tool used that differs. One way is more traditional (older) and involves using Modkeymap. Other ways: LIRC (even if you are not using an Infrared remote.) The kernel interface evdev in combination with the ir-keytable tool. Other tools will be mentioned here eventually.
Contents
Modkeymap
background
xmodmap is a utility for modifying keymaps and pointer button mappings in Xorg / XFree86 / Xwindows Server.
"When you change the display’s or keyboard backlight’s brightness using keyboard hotkeys, the change in brightness should be shown in a confirmation bubble with a gauge. "This is the KNotification API. https://wiki.ubuntu.com/NotifyOSD#Volume_changes The Xfce desktop I see it for volume up and down, those seem to be mapped in the distribution I use - Xubuntu.
What's it trapped by? Well the kernel generates the scancode, which is different from a keycode. Don't confuse the two. There is a mapping for scancode to keycode at the kernel level. When you map a scancode to a different key with xmodmap there isn't a problem unless the scancode is already assigned to something, a good example is volume up and down. The new mapping doesn't apply after running xmodmap, however, will stop functionality of the volume control. After you reboot the system the new mapping will take effect by those that were previously intercepted. Gnome, KDE and Xfce will intercept some of the hotkeys. Adjusting the volume or pressing mute will result in a screen icon appearing generated by the KNotification API and resulting in the change occurring in PulseAudioMixer and/or ALSA.
Keycode values once were mapped to a text string called a keysym in a file called XF86keysym.h that is compiled into the kernel. When you install a distribution such as Mythbuntu the keysym strings are already in the kernel. They are like global constants that can be used by other software. The string values are used globally without the leading 3 characters. Not all of the keysym constants cover every hotkey. Multimedia keyboards with volume controls:
Volume Up and Down: keycode 176 = XF86AudioRaiseVolume and keycode 174 = XF86AudioLowerVolume
configuration and activation
1. Find your keycodes
First you need to install a utility such as xev to get the keycodes for the buttons you wish to map. Many of these buttons are relatively standard, however, not standardized. Some keycodes differ from one manufacturer to the next.
2. Install and configure Xmodmap
It should already be installed. If not...
apt-get install xmodmap
See the default X key mapping table.
xmodmap -pke
See also: event_key_remap' in 'xorg.conf'.
Now create the .Xmodmap or modify the existing file. It is not necessary to do this under a privileged account. You want to do it as the MythTV user account. Create the xmodmap mapping file.
vi ~/.Xmodmap
Populate it with the mappings you desire. Take a look at our example file for the Aerb Remote Control MX3:
! Keymap for Aerb Remote Control MX3 ! 172 Play / Pause ! 174 Stop ! 056 Back (Rewind) ! 041 Forward ! 173 Last track ! 171 Next track ! 121 Mute ! 122 Volume up ! 123 Volume down keycode 176 = Left keycode 216 = Right keycode 173 = Home keycode 171 = End keycode 69 = Escape keycode 172 = space keycode 135 = m M keycode 180 = Menu keycode 163 = i I keycode 68 = w W
3. Test the configuration
As a non privileged user run the following command:
xmodmap .Xmodmap
Any key mappings not being intercepted by Xfce or a plugin will become usable immediately. If there is an error in your .Xmodmap file the mapping will abort completely. You will see the error message on console along with line number. Correct the errors and try again until there are no errors.
4. Reboot the system
If you do not reboot the system then you will find some of your key mappings will not come though. On Mythbuntu you will find that buttons such as PLAY are mapped to activate the DVD drive. If you try to remap to something like in our example the change will not be effective until the system is restarted. I know, kinda lame like the old Microsoft Windows. Technically a system restart is not necessary if X.org and some other processes are restarted, however, it is just easier to reboot.
Creating mappings for actions
Use xfce keyboard settings (on xfce4-settings-manager) to customize keymaps to actions such as opening a program. You can create an action for something like "Launch web browser" or "launch MythTV Frontend."
- Multimedia Key Mapping in Mythbuntu using xmodmap
- Playing with xbindkeys
- Multimedia Keys
- USB Device Diagnostics in Linux
LIRC
Here is a guide on Lifehacker.com
edev
evdev is a generic input event interface in the Linux kernel. It generalizes raw input events from device drivers and makes them available through character devices in the /dev/input/ directory.
A guy named Richard Atterer documented the process of using this tool to map hotkeys on his web site:
His permission is needed to copy the text here. Hopefully his site remains online. It is an excellent guide.