LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Hardware (http://www.linuxquestions.org/questions/linux-hardware-18/)
-   -   A how-to for Logitech multimedia keys (http://www.linuxquestions.org/questions/linux-hardware-18/a-how-to-for-logitech-multimedia-keys-53834/)

Scrapz 04-07-2003 09:17 AM

A how-to for Logitech keyboard multimedia keys
 
I've actually known this for awhile (when I had my Logitech iTouch) but when I got my new Logitech Wireless Pro, it had an extra 6 or so buttons ONTOP of the 12 buttons the iTouch already had. Needless to say, I got them all working, and now I will share my story ;)

(As a note, this is using the wireless keyboard using the PS/2 adapter, although it should *theoretically* work in USB as well.)

Firstly, log in as root and open the file /usr/X11R6/lib/X11/XKeysymDB with your favorite editor. Scroll to the end of the file, and add the following to the end of the file.
Code:

logitech_user          :10090000
logitech_myhome        :10090001
logitech_email          :10090002
logitech_search        :10090003
logitech_favorites      :10090004
logitech_mute          :10090005
logitech_voldown        :10090006
logitech_volup          :10090007
logitech_playpause      :10090008
logitech_stop          :10090009
logitech_rew            :1009000A
logitech_fwd            :1009000B
logitech_windowsleft    :1009000C
logitech_windowsright  :1009000D
logitech_shopping      :1009000E
logitech_itouch        :1009000F
logitech_sms            :10090010
logitech_webcam        :10090011
logitech_media          :10090012
logitech_arrow          :10090013
logitech_go            :10090014

That basically covers all the keys on the Wireless Pro. If you have an iTouch, then obviously some of those buttons arent going to be there, so you dont have to specify the ones that you dont have. I havnt tested it, but it should still work fine otherwise.

Save and close that file (its opened in read-only mode so you may have to force the write, :wq! in vim) and exit out of root. Log in as your user and edit the file ~/.xmodmap (or /home/username/.xmodmap) - the file may or may not already exist. Either way, add this to the end of the file:
Code:

keycode 144 = logitech_rew
keycode 145 = logitech_sms
keycode 146 = logitech_webcam
keycode 147 = logitech_itouch
keycode 148 = logitech_shopping
keycode 153 = logitech_fwd
keycode 160 = logitech_mute
keycode 162 = logitech_playpause
keycode 164 = logitech_stop
keycode 174 = logitech_voldown
keycode 176 = logitech_volup
keycode 178 = logitech_myhome
keycode 223 = logitech_user
keycode 229 = logitech_search
keycode 230 = logitech_favorites
keycode 233 = logitech_go
keycode 234 = logitech_arrow
keycode 236 = logitech_email
keycode 237 = logitech_media

...omitting the ones you dont have if you want.

Some window managers load the .xmodmap file by default, sometimes its loaded by GDM or XDM (if you use it) - however, dont quote me on that. Check the menu settings for what it does and what files it loads when starting your window manager.

Or, if you're like me and start your window manager manually by typing startx at the prompt, then add this as the FIRST line in your ~/.xinitrc
Code:

xmodmap ~/.xmodmap
So, we've made it that X can 'understand' the extra keys as a keypress when we press them, now we just have to bind events to them. You can bind whatever you want to whatever multimedia key you want. You might want to have it so it loads your email program when you hit the 'Email' button, and load your homepage in your favorite browser when you hit the 'My Home' button, or you can have it so it plays a certain song, or any other command... anything you want...

The method of binding the keys varies from WM to WM, I only know how to set binding for two; fluxbox and Sawfish. Now, assuming that fluxbox, openbox and blackbox are all relatively the same, this method should work the same for all three. Other WM's like Gnome or KDE will require you to do a little bit of reading (sorry ;) ) but it should be readily available, and chances are has a nice little wizard to help you do it.

Anyway, for fluxbox commands go in the form of None {logitech_button} :ExecCommand {command} (the 'None' makes it so you dont need to press a secondary button like 'Shift' or 'Alt' for it to work) and it gets put in your ~/.fluxbox/keys file. A perfect example of this (from my setup) are as follows:
Code:

None logitech_rew :ExecCommand xmms --rew &
None logitech_sms :ExecCommand gaim &
None logitech_webcam :ExecCommand xawtv &
None logitech_itouch :ExecCommand echo ">> iTouch"
None logitech_shopping :ExecCommand echo ">> Shopping"
None logitech_fwd :ExecCommand xmms --fwd &
None logitech_mute :ExecCommand ~/bin/logitechctl mute &
None logitech_playpause :ExecCommand xmms -t &
None logitech_stop :ExecCommand xmms --stop &
None logitech_voldown :ExecCommand vol -2 &
None logitech_volup :ExecCommand vol +2 &
None logitech_myhome :ExecCommand opera &
None logitech_user :ExecCommand killall fluxbox
None logitech_search :ExecCommand nautilus &
None logitech_favorites :ExecCommand Eterm --buttonbar=0 --geometry 80x24 --scrollbar=0 -O --tint 0x4a4a4a &
None logitech_go :ExecCommand echo ">> Go"
None logitech_arrow :ExecCommand echo ">> Arrow"
None logitech_email :ExecCommand sylpheed &
None logitech_media :ExecCommand echo ">> Media"

...the parts where I specified the command 'Echo ">> foo"' is simply a placeholder for when I want to put a proper command in there. Typically, you wont see it but you can if you do a bit of searching. You could replace it with anything if you want, I just made it that. (I dont really have a use for all these buttons yet...)

The Sawfish keybindings go in the file ~/.sawmill/custom file, and looks like this:
Code:

(custom-set-keymap (quote global-keymap) (quote (keymap
  ((run-shell-command "xscreensaver-command -lock") . "logitech_user")
  ((run-shell-command "mozilla -chrome") . "logitech_favorite")
  ((run-shell-command "mozilla -mail") . "logitech_email")
  ((run-shell-command "mozilla -chrome http://www.google.com") . "logitech_search")
  ((run-shell-command "/home/jl/bin/logitechctl mute") . "logitech_mute")
  ((run-shell-command "aumix -v-10") . "logitech_voldown")
  ((run-shell-command "aumix -v+10") . "logitech_volup")
  ((run-shell-command "~/bin/logitechctl playpause") . "logitech_playpause")
  ((run-shell-command "xmms --stop") . "logitech_stop")
  ((run-shell-command "xmms --rew") . "logitech_rew")
  ((run-shell-command "xmms --fwd") . "logitech_fwd")
)))

...thats untested, but its what I've read, so it should *theoretically* work. Doesnt hurt to do a bit of reading up on it though.

Then restart X. Thats it. Test your buttons by pressing them (obviously ;) ) and see if they work. If they dont work, then it might be that your ~/.xmodmap didnt get loaded. Again, a little reading up on that, but if you put that 'xmodmap' command in your .xinitrc file (if you start X manually) then its possible that the commands you bound the keys to are invalid. Check your logs (or flip to console1 if you're lucky) and check for any errors messages.

Any questions, just ask I guess ;) I'll do the best to answer them.

Scrapz :p

jpbarto 04-07-2003 10:27 AM

Ok, I've got extra buttons... but the keyboard's not a logitech. I think I remember reading somewhere that there's a utility I can run, then press a key, and the utility will tell me what the equivalent scancode is (the 10090010 type number that must be entered into the keyboard DB... what is the name of that utility?

Scrapz 04-07-2003 10:38 AM

The program you're thinking of is xev - that will however return raw keycodes, not the '10090000' number that you need. I think that number is based on the manfacturer ID, so you cant just use any number. There are websites which list the raw key codes of any given brand of keyboard, but converting those keycodes to something you can use id the tricky part. I guess so research is in order ;)

Scrapz :p

Scrapz 04-07-2003 10:50 AM

Actually, I could have missed a point. It would seem that scrolling through the XKeysymDB file that the Logitech definitions used the next available number in the sequence. So, theory would have it, you could rename the 'logitech' bit to whatever you want (provided you changed 'logitech' anywhere else it appeared' and it would work. That is hwoever a rough guesstimate. I dont believe that other brands would use the exact same keycodes for the multimedia buttons. Good chance most of them will, good chance some of them wont. By using xev you can press the button and it will tell you the keycode, and you subsitute it for that. If anyone wants to make a 'Microsoft Multimedia keyboard How-to' variaition, then thats probably a good thing. A bit of messing around, especially on the funkier keyboards with 20 or som buttons, but well worth it in the end ;)

Scrapz :p

jpbarto 04-07-2003 12:16 PM

thanks for the tips and the great howto!

jstn 04-07-2003 02:43 PM

logitech howto ...
 
Scrapz - great howto, it's worked well so far in flux. i was wondering, how do you get the volume wheel to work? i've got a logitech elite keyboard, it's black with the multimedia keys, etc at the top.

also what is the app you use to control the pcm volume? it's just vol? Mind sending a link to get that app?

thanks in advance.

-jstn

Scrapz 04-07-2003 05:37 PM

That 'vol' progam that I use is basically just a simple BASH script that tells aumix what to do. SInce I also have rear speakers, just using this one command named 'vol' helps to remember things. I use 'aumix' to set my volume, and the vol BASH script simply has:
Code:

#!/bin/bash

aumix -v %1
aumix -o %1

...putting that in /usr/bin (as root of course) - then binding the command vol +5 to logitech_volup and vol -5 to logitech_voldown. You can also specify the volume in percentage. ie: vol 90 will set the colume to 90%

jstn 04-07-2003 05:46 PM

Cool, I ended up just doing the same thing but i put aumix -v +2 in my flux keys file.

i thought it would be tougher to get this keyboard tweeked to my liking but it was pretty easy :D

where/how did you read about how to get this keyboard working? mind posting your resource? tnx!

-jstn

Scrapz 04-07-2003 07:19 PM

Hmm, I dont have the exact link... but its over at linuxlabs.com IIRC - the one and only link I found that told me what I wanted ;)

Scrapz :p

Daem0hn 07-12-2003 01:35 AM

Thank You SOO much for writing such a great how to, i have now got my logitech cordless elite keyboard working in Gnome 2

i will quickly describe how i got the keys working in gnome 2:

after adding xmodmap ~/.xmodmap to the .xinitrc file
launch gconf-editor
# gconf-editor
now click on apps
click on metacity
click on global_keybindings
it is in this folder that the key shortcuts are stored
to make a command execute at a keypress, edit one of the keys named
run_command_X
where X is a number
now into the Key Value text box, type the name of one of the keys you declared in ~/.xmodmap
for example "logitech_search" (without the quotes)
each run_command_X is linked to command_X in
[/apps/metacity/keybinding_commands]
when you have browsed to the dir in gconf-editor
find the key command_X (obviously X in command_X and run_command_X should be the same)
now edit teh command_X key, and in the Key Value type the command you wish to execute


thats it :)


once again, thanks for the great how-to, keep up the good posting!!!

EDIT: i would just like to point out that if the volume scripts arent working try replacing %1 with $1, the $1 means first argument after the command

/bin/bash 11-26-2003 01:32 AM

Logitech Elite Keyboard for KDE

First of all follow Scrapz most excellent HOWTO to get to the point where you can actually use the keys. Then I'll show you how to get them to work in KDE.

Here is the GUI method of configuring the keyboard in KDE.

K Menu -> Configuration -> KDE -> Accessibility -> Keyboard Shortcuts
At the top of the page select the Command Shortcuts tab.
Now you get a regular menu which should resemble the normal K Menu. Lets say you want to assign KMail to the EMail button. You would click through the menu Networking -> Mail and select KMail.
Below the menu are two choices None and Custom, with None being selected. Select Custom and you will get a popup menu with options Primary / Alternate and Primary is selected. So leave Primary selected and also you could select Multi-key if you wanted to make a multi-key hotkey. So we will leave multi-key un-checked. Now all you have to do is press the EMail button an you should see Logitech_email pop up beside the KMail application.

You can do this for any of the keys on the Logitech Elite. For those who like to do things by hand the config file is ~/.kde/share/config/khotkeysrc and here are a few line from the file so you'll have an idea of the files format.

[Main]
Num_Sections=11

[Section1]
Name=K Menu - Networking/WWW/konqbrowser.desktop
Run=Networking/WWW/konqbrowser.desktop
Shortcut=Logitech_myhome

[Section2]
MenuEntry=true
Name=K Menu - Multimedia/Video/Camorama.desktop
Run=Multimedia/Video/Camorama.desktop
Shortcut=Logitech_webcam

[Section3]
MenuEntry=true
Name=K Menu - Configuration/Configure your computer.desktop
Run=Configuration/Configure your computer.desktop
Shortcut=Logitech_search

[Section4]
MenuEntry=true
Name=K Menu - Networking/Mail/KMail.desktop
Run=Networking/Mail/KMail.desktop
Shortcut=Logitech_email

So now you are going to ask, "how do I make a key run an application or script that isn't in the menu? Well you put it in the menu. So far thats the only way I've found to do it. I tried every which way to put commands in the config file to run different applications and could not find the proper syntax to make it work. And since there seems to be no documentation or man pages for khotkeys you are stuck doing it through the menu method. But this isn't so bad as it would seem. I'll show you how I made the multimedia keys work for XMMS.
Code:

xmms --help
-h, --help              Display this text and exit.
-n, --session          Select XMMS session (Default: 0)
-r, --rew              Skip backwards in playlist
-p, --play              Start playing current playlist
-u, --pause            Pause current song
-s, --stop              Stop current song
-t, --play-pause        Pause if playing, play otherwise
-f, --fwd              Skip forward in playlist
-e, --enqueue          Don't clear the playlist
-m, --show-main-window  Show the main window.
-v, --version          Print version number and exit.

I'll be assigning the keys like this:
Logitech_pauseplay xmms --play-pause
Logitech_stop xmms --stop
Logitech_rew xmms --rew
Logitech_fwd xmms --fwd

So how do I get these commands in the menu? Simple, Menudrake. I startup menudrake:
K Menu -> Configuration -> Other -> Menudrake
Now here's the "trick". I dont want to clutter up my menu with a bunch of xmms links so I open the .hidden section, create a folder called Logitech-Elite and I put the menu items in there. Once I create the Logitech-Elite folder I select Add application. In the Title I put XMMS-pauseplay, In the command I put /usr/bin/xmms --play-pause. I save that then click Add application and do the same for stop, fwd and rew. Now I select save from Menudrake main menu. Then I go back to K Menu -> Configuration -> KDE -> Accessibility -> Keyboard Shortcuts. I follow the same procedure as before to add the new keys to khotkeys. If you are wondering what the khotkeysrc entries look like, here they are.

[Section9]
MenuEntry=true
Name=K Menu - .hidden/Logitech-Elite/XMMS-pauseplay.desktop
Run=.hidden/Logitech-Elite/XMMS-pauseplay.desktop
Shortcut=Logitech_playpause

[Section10]
MenuEntry=true
Name=K Menu - .hidden/Logitech-Elite/XMMS-Forward.desktop
Run=.hidden/Logitech-Elite/XMMS-Forward.desktop
Shortcut=Logitech_fwd


So you could write a script that does amazing things and assign it to one of your handy-dandy Elite keys.

Now in my opinion the KDE method seems way harder than the other methods presented in this thread. I was hoping I could just edit the khotkeysrc file and add stuff from there but like I said I had no luck doing it that way. Maybe someone smarter than me can tell me what I was doing wrong.

Anyway I hope maybe this helps someone.

jcmaco 12-10-2003 06:57 PM

I tried /bin/bash's technique but every time I press a key there's a new taskbar item that appears named 'Pause', 'Previous', etc (depending on wich keys I pressed). The item has a revolving sand-clock, after 30 seconds it closes the window. I am using the command "xmms -p". I have also tried this command "xmms-shell -e previous" with the same effect.

BruceCadieux 12-11-2003 05:02 AM

Much easier way is to use the tool here. http://lineak.sourceforge.net/

http://lineak.sourceforge.net/index.php?nav=screenshots

I have been using it with several different keyboards for quite some time.

/bin/bash 12-12-2003 04:25 PM

OK the Prev and Next or Fwd Rew keys send multiple key strokes if you're not quick when you press them. But the keys work.

I agree the "spinning hourglass" is annoying.

I'm posting another thread on this subject as the new XFree86 has this built in and makes all this mute. I'll post it here to, just in case someone searching finds this thread first.

/bin/bash 12-12-2003 04:48 PM

OK this is gonna be a brief tutorial on setting up the Logitech Elite Keyboard for use under KDE and X. XFree86 already has a keyboard layout premade for the Logitech-Elite keyboard. It's actually slightly different (the Elite has 2 additional keys, Go and Back) but other than that the layout is the same.

Look in the file /etc/X11/xkb/symbols/inet

At approximately line #1118 you should have an entry like this:

partial alphanumeric_keys
xkb_symbols "logicdn" {
name[Group1]= "Logitech Cordless Desktop Navigator";
...
...
...
}



If your inet file doesn't have this entry then you probably have an older version. I got mine from XFree86 beta. But not to fear you can copy mine (copy everything between the code tags below into /etc/X11/xkb/symbols/inet) into your inet file and it will work just the same. Just choose an appropriate place to paste it, be careful not to paste between any { of these } only on the outside of them i.e. after } and before the next {.


I wanted to make the Go and Back keys work (the two little keys on the left side of the keyboard next to the scroll wheel) so what I did was I copied thew whole entry for the "Logitech Cordless Desktop Navigator" and modified it and renamed it like this:
Code:

partial alphanumeric_keys
xkb_symbols "logielite" {
    name[Group1]= "Logitech Elite";

    // Media keys
    key <I20>        {        [ XF86AudioMute                ]        };
    key <I6D>        {        [ XF86AudioMedia        ]        };
    key <I2E>        {        [ XF86AudioLowerVolume        ]        };
    key <I30>        {        [ XF86AudioRaiseVolume        ]        };
    key <I22>        {        [ XF86AudioPlay, XF86AudioPause ] };
    key <I24>        {        [ XF86AudioStop                ]        };
    key <I10>        {        [ XF86AudioPrev                ]        };
    key <I19>        {        [ XF86AudioNext                ]        };

    // Left side
    key <I69>        {        [ XF86Go                ]        };
    key <I6A>        {        [ XF86Back                ]        };
    key <I5F>        {        [ XF86User                ]        };

    key <I6C>        {        [ XF86Mail                ]        };
    key <I11>        {        [ XF86Messenger                ]        };
    key <I12>        {        [ XF86WebCam                ]        };

    // Right side
    key <I13>        {        [ XF86iTouch                ]        };
    key <I65>        {        [ XF86Search                ]        };
    key <I14>        {        [ XF86Shop                ]        };
    key <I66>        {        [ XF86Favorites                ]        };
    key <I32>        {        [ XF86HomePage                ]        };

    // Extended function keys
    key <I3B>        {        [ XF86New                ]        };        // F1
    key <I3C>        {        [ XF86Reply                ]        };        // F2
    key <FK13>        {        [ XF86MailForward        ]        };        // F3
    key <FK14>        {        [ XF86Send                ]        };        // F4
    key <FK15>        {        [ Undo                        ]        };        // F5
    key <FK16>        {        [ Redo                        ]        };        // F6
    key <FK17>        {        [ Print                        ]        };        // F7
    key <I42>        {        [ XF86Save                ]        };        // F8
    key <I43>        {        [ XF86MyComputer        ]        };        // F9
    key <I44>        {        [ XF86Documents                ]        };        // F10
    key <I57>        {        [ XF86Pictures                ]        };        // F11
    key <I58>        {        [ XF86Music                ]        };        // F12

};

NOTE: The two bold entries are what I added to enable the two side buttons Go and Back, also I renamed XF86Stanby to XF86User which matches the keyboard.

Now if you go to K Menu -> Configuration -> KDE -> Accessibility -> Keyboard Layout. Now check Enable Layouts and this should allow you to select a Keyboard from the Keyboard model pull-down menu. There are quite a few if you have the latest XFree86 sources. But unfortunately Logitech Elite is not one of them... yet! Here's what you do to add it to the list.

Edit /etc/X11/xkb/rules/xfree86.lst

Scroll down to the Logitech entries and add a new entry like this.

Code:

  logicdn        Logitech Cordless Desktop Navigator
  logidak        Logitech Deluxe Access Keyboard
  logielite        Logitech Elite
  logiik        Logitech Internet Keyboard
  itouch        Logitech iTouch

Once again what is in bold is what I added to the file. NOTE: I put mine in alphabetical order like the rest, I don't think it matters.

So now you can go back to K Menu -> Configuration -> KDE -> Accessibility -> Keyboard Layout and when you use the Keyboard model pull-down menu the Logitech Elite should be listed along with the others.



So now your keyboard is ready to start assigning keys in KDE. But what if you don't use KDE and you want to be able to define the keyboard for say Blackbox or XFce? In that case you need to assign the keyboard from the /etc/X11/XF86Config-4 file. Everything is already setup to do that you only need to edit one more file.

Edit the file /etc/X11/xkb/rules/xfree86. Scroll down to the inet keyboards section
! $inetkbds =

Then I put the lable logielite in the same order I had placed it in the inet file (right after the freedom navigator), like this:
Code:

! $inetkbds = airkey acpi scorpius \
              brother \
              btc5113rf btc5126t btc9000 btc9000a \
              cherryblue cherrybluea \
              chicony chicony9885 \
              compaqeak8 compaqik7 compaqik13 compaqik18 armada presario ipaq \
              dell inspiron \
              dexxa diamond genius \
              ennyah_dkb1008 \
              hpi6 hp2501 hp2505 hp5181 hpxe3gc hpxe3gf hpxe4xxx hpzt11xx \
              hp500fa hp5xx \
              honeywell_euroboard \
              rapidaccess rapidaccess2 rapidaccess2a \
              ltcd logicdit logicdp logicdpa logicdpa2 logicdo logicfn logielite \
              logicdn logidak logiik itouch logiitc logiik logiink itouchin \
              mx1998 mx2500 mx2750 \
              microsoftinet microsoftpro microsoftprose microsoftoffice \
              oretec \
              propeller \
              qtronix \
              samsung4500 samsung4510 \
              sk1300 sk2500 sk6200 sk7100 \
              sven symplon toshiba_s3000 trust trustda yahoo

Thats it. Now just edit XF86Config-4 and change your keyboard section like this:

Code:

Section "InputDevice"
    Identifier "Keyboard1"
    Driver "Keyboard"
    Option "XkbRules" "xfree86"
    Option "XkbModel" "logielite"
    Option "XkbLayout" "us"
EndSection

Of course you can verify the keys are working properly by running xev and pressing some keys. I verified the keys I added are working:
Code:

KeyPress event, serial 27, synthetic NO, window 0x2600001,
    root 0x41, subw 0x0, time 179142, (181,2), root:(870,22),
    state 0x10, keycode 234 (keysym 0x1008ff26, XF86Back), same_screen YES,
    XLookupString gives 0 characters:  ""

KeyRelease event, serial 27, synthetic NO, window 0x2600001,
    root 0x41, subw 0x0, time 179362, (181,2), root:(870,22),
    state 0x10, keycode 234 (keysym 0x1008ff26, XF86Back), same_screen YES,
    XLookupString gives 0 characters:  ""

KeyPress event, serial 27, synthetic NO, window 0x2600001,
    root 0x41, subw 0x0, time 180752, (181,2), root:(870,22),
    state 0x10, keycode 233 (keysym 0x1008ff5f, XF86Go), same_screen YES,
    XLookupString gives 0 characters:  ""

KeyRelease event, serial 27, synthetic NO, window 0x2600001,
    root 0x41, subw 0x0, time 180945, (181,2), root:(870,22),
    state 0x10, keycode 233 (keysym 0x1008ff5f, XF86Go), same_screen YES,
    XLookupString gives 0 characters:  ""

As you can see the XF86Go and XF86Back indicate that the keys are working.

Since each Window manager / Desktop environment has a different method of assigning apps to the keys on a keyboard I'll not go over that here. I believe that subject has been covered in another thread already, so you should try another search for logitech keyboard.

So I guess thats about it. Hopefully this has helped you get your Logitech Elite keyboard working.

Happy Linuxin'


All times are GMT -5. The time now is 09:49 PM.