Internet Hotkeys

My keyboard is a Logitech Internet Pro and it has 7 keys at the top for special functions that I’ve never really made use of in Kubuntu, but now I’ve got them all functioning using the handy application “hotkeys”.

Here’s what I did to get them working:

First the actual keys are labelled

Media ,Play/Pause,Mute,Vol +,Vol -,Favorites,Email,WWW

I tried to use KDE keyboard variants to get them working but this didn’t really work that well so I installed the application hotkeys:-

sudo apt-get install hotkeys

The hotkeys application intercepts keys and processes actions according to a couple of configuration files.

The first config file is the definition of the keycodes that are generated by your keyboard and what hotkeys command name to map them to. There is one definition file for each type of keyboard that hotkeys supports. To see the list of supported keyboards run the command

hotkeys -l

This actually reads the contents of various .def files from the config directory ( /usr/share/hotkeys in Kubuntu)

The second config file defines what action or programs are run when the various keys are pressed. By default in Kubuntu this is installed as /etc/hotkeys.conf. The best way to customise this is to create a directory in your homedir called .hotkeys and copy /etc/hotkeys.conf into there.

mkdir ~/.hotkeys

cp /etc/hotkeys.conf ~/.hotkeys/hotkeys.conf

The hotkeys.conf file consists of simple key/value pairs and you can edit it to launch the applications you require. The setting for Kbd defines what keyboard definition file is loaded when you run hotkeys.

Here is the final version of my hotkeys.conf ( note that Kbd is set to logitech-internet-pro which is not a standard definition, it’s one I created myself. More of which anon.)

############################################################
# Global configuration for hotkeys #
############################################################

# These are the default values.
# A line starting with # is a comment.

### Specify the default keyboard (without the .def extension) so you
### don’t need to specify -t every time

#using my own definition based on itouch
Kbd=logitech-internet-pro

Play=amarok –pause

WebBrowser=firefox
Email=firefox gmail.com
Favorites=dolphin

# osd_font=-arphic-ar pl kaitim big5-bold-i-normal–0-250-0-0-c-0-*-*
### For the color, you can either use the strings in /etc/X11/rgb.txt,
### or use the RGB syntax #RRGGBB, e.g. ##A086FF
# osd_color=LawnGreen
# osd_timeout=3
### osd_position is either ‘top’ or ‘bottom’
# osd_position=bottom
# osd_offset=25

The syntax is pretty obvious, when the WebBrowser key is pressed the command firefox is executed. To test the config just run the command

hotkeys

You’ll see a splash screen appear briefly and the application is now running. Press a key and you see an on screen display in green telling you what is happening and the relevant action will be executed.

You’ll notice I haven’t mapped anything for mute, volume etc. these all work with the defaults.

To get hotkeys to always be loaded when I am running KDE I added a link to the hotkeys executable to the .kde/Autostart directory:-

cd ~/.kde/Autostart

ln -s /usr/bin/hotkeys hotkeys

The Play/Pause keys executes “amarok –pause” , unfortunately from the command line this is not a toggle thus I can press the “Play/Pause” key and it will pause amarok but a second press won’t restart it. The command for that is “amarok –play” so I have mapped this to my Media key at the moment.

The “Media” key is not a standard hotkeys command name but the keyboard definition files allow you define commands to executed directly in there. The “key” (pun intended) to the keyboard definition files are the keycodes your keyboard generates.

I started with the itouch.def file and found it worked for most of they keys. Using the excellent application “xev” I was able to discover what keycodes my keyboard was generating and create my own variant called logitech-internet-pro.def the contents are reproduced below. I shall have to see if there is anywhere appropriate I can upload the file to make it available for others.

<?xml version=”1.0″?>

<definition>

<config model=”Logitech Internet Pro”>

<Play keycode=”162″/>

<VolUp keycode=”176″ adj=”2″/>
<VolDown keycode=”174″ adj=”2″/>
<Mute keycode=”160″/>

<WebBrowser keycode=”178″/>
<Email keycode=”236″/>
<Favorites keycode=”230″/>

<!– Feel free to customize this – the media key –>

<userdef keycode=”237″ command=”amarok -p”>Amarok</userdef>

</config>

<contributor>
<name>Simon Stanford</name>
<email>sjs atraetsel dot co dot uk</email>
</contributor>

My next task is to see if I can get the Play/Pause button to actually act as a toggle and for this I think I am going to need to use dcop to interrogate the state of amarok and/or pass it the appropriate command.

Advertisements

5 thoughts on “Internet Hotkeys

  1. Pingback: Kubuntu Hardy Heron Upgrade « Harsh but fair

  2. Cheers D.J. a useful “undocumented feature” well at least as far as “man amarok” is concerned.

    As you can read above I found a way to do play/pause using dcop but this won’t work when amarok 2.0 comes out and uses dbus whereas presumable amarok -t will still work with amarok 2.0

    Interesting choice of “-t” wonder what that stands for?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s