Notes on seeking wisdom and crafting software

How to : Create keyboard shortcuts for MPC in e17

In this article, we will just make our CLI life a bit easier by implementing a few keyboard shortcuts for our Music Player Daemon (MPD) These keyboard shortcuts will take care of common Multimedia Tasks such as Play, Pause, Raise/Lower Volume, Stop etc.. I will speak about configuring these keyboard shortcuts in Enlightenment 17 (e17) desktop manager. Lets begin :

1. **Find the keycodes of shortcut keys**
</p>
This step is necessary if you are going to use Multimedia Keys as
shortcuts..otherwise if you're using common shortcuts (e.g :
CTRL+ALT+ P for play) please skip this :)  

We need to know the keycodes of the Multimedia keys and then map
them so that they can be used as shortcuts. Open up a Terminal type
in  

`xev`  

A new window (Event Tester) would popup. Put that window under focus
and then press the multimedia keys.  

![](http://img104.imageshack.us/img104/3023/xevqh3.jpg)  

Then note the *keycode* in the outputs that show up in the terminal
(ref. figure). We need to map these keycodes to the corresponding
keys. To do that open the file */usr/lib/X11/XKeysymDB* or
*/usr/share/X11/XKeysymDB* and look for the keywords "Play" etc..
Now create a new file *\~/.Xmodmap* then put the following text into
the file :  

`keycode ppp = XF86AudioPlay  `

keycode qqq = XF86AudioNext  

keycode rrr = XF86AudioPrev</code>  

where ppp, qqq, rrr are the 3 digit keycodes you obtain for a
Multimedia Key from xev. Also replace *XF86AudioPlay* as per your
*XKeysymDB*  

Now insert the following command into session startup :  

`xmodmap /home/user_name/.Xmodmap`  

<p>

2. Bind the keys in Enlightenment 17 (e17)

</p>
To include any keyboard shortcut in e17 we need to use the following
command :  

`enlightenment_remote -binding-key-add OPT1 OPT2 OPT3 OPT4 OPT5 OPT6`Where
the conventions are :  

> CONTEXT = OPT1 (e.g : ANY)  
> </p>
> KEY = OPT2 (e.g : "Delete")  
> MODIFIERS = OPT3 (e.g : CTRL|ALT i.e ctrl or alt)  
> ANY\_MOD = OPT4 (e.g : 0)  
> ACTION = OPT5 (e.g : "exit")  
> <p>
> PARAMS = OPT6 (e.g : "")

In order to implement the play/pause shortcut we can use  

</p>
`enlightenment_remote -binding-key-add ANY XF86AudioPlay NONE 0 "exec" "mpc toggle"`  

  

Similarly here are the other commands :`  `

enlightenment\_remote -binding-key-add ANY XF86AudioStop NONE 0
"exec" "mpc stop"  

enlightenment\_remote -binding-key-add ANY XF86AudioRaiseVolume NONE
0 "exec" "mpc volume +5"  

enlightenment\_remote -binding-key-add ANY XF86AudioLowerVolume NONE
0 "exec" "mpc volume -5"  

enlightenment\_remote -binding-key-add ANY XF86AudioNext NONE 0
"exec" "mpc next"  

enlightenment\_remote -binding-key-add ANY XF86AudioPrev NONE 0
"exec" "mpc prev"</code>  

<p>

References :

Using Multimedia Keys @ Gentoo Wiki

Keybindings @ e17 user guide

technorati tags:mpd, mpc, e17, enlightenment, keyboard+shortcuts, shortcut+keys, mp3, suse