[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Linux.com - Mapping Extras Function Keys with XFree 4.0 <http://www.linux.com/desktops/newsitem.phtml?sid=1&aid=11801>



 
    
Title: Linux.com - Mapping Extras Function Keys with XFree 4.0
    | S | D | N    NEWSFORGE · GEOCRAWLER · SOURCEFORGE My OSDN · PARTNERS · AFFILIATES   


Linux.com
 
 Search Linux.com: 
  
 
 Read HOWTOs: 
Linux HOWTOs @ Linux.com
 
Go to Section:
Main Desktops Development Download FirstStep Games Hardware HOWTOs Jobs Links Linux.com Live! Linux User Groups Multimedia Support  - Questions Sysadmin Tuneup LinuxGram (offsite) [ List All ]
  Saturday the 24th   About :: Contact :: Link Us! :: Logos :: Print :: Sections :: Staff :: Volunteer  -  [ Log In ] February 2001  

 Desktop News 

GNOME 1.4 Update
Fri, 16 February 2001
The first edition of a weekly series of GNOME 1.4 Updates has been posted.

Gnapster author interview
Mon, 5 February 2001
The author of Gnapster, Josh Guilfoyle, was recently interviewed at Linux Brazil.

New Person Behind KDE
Fri, 2 February 2001
This weeks featured person in KDE's 'People behind KDE' is Jing-Jong Shyue.

Another Nat Friedman interview
Fri, 2 February 2001
As if everyone involved with GNOME hasen't been interviewed already, Nat Friedman of Ximian GNOME fame was interviewed at LinuxWorld in New York recently.

More News

 Resources 

Use our news!
Snarf the latest headlines from Linux.com for use on your site.

 

Desktops

Mapping Extras Function Keys with XFree 4.0
  by Josh Boudreau - Fri, 23 Feb 2001 09:26:25am

Introduction

This article will explain the process of getting your keyboard's extra function keys to work in XFree86 4.0.X. This article uses the Logitech iTouch keyboard with XFree86 4.0.2 as an example. This method has not been tested with other keyboard models and XFree86 versions other than the ones used by myself. Your results may vary depending if your keyboard is supported by XFree86 4.0 or not. As far as I know, this is an undocumented feature that has been incorporated in XFree86 4.0.

The way this works is that you have to get the scancode of your extra function keys with the xev program, and assign names and keysyms to the keys to be able to use them with X11. I suggest you backup the files we are going to edit in case something goes wrong and you need to restore the original configuration.

Getting your Keys Scancodes

Use the xev program that omes with every XFree86 distribution to get your key's scancodes. The default install location of this program is in /usr/X11R6/bin/xev. When you run this program you'll be looking at a white window with a black square in the middle. This program is used to record X11 Events such as mouse clicks, keyboard keys, etc.

Now that you have the program running, try pressing one of your keyboard's extra function keys. In the terminal from which you launched xev, the output should be similar to this: xev output:
----------------------------------------------------------------
KeyPress event, serial 29, synthetic NO, window 0xe00001,
root 0x4d, subw 0x0, time 3608986670, (524,-135), root:(589,304),
state 0x0, keycode 223 (keysym 0x0, NoSymbol), same_screen YES,
XLookupString gives 0 characters: ""

KeyRelease event, serial 29, synthetic NO, window 0xe00001,
root 0x4d, subw 0x0, time 3608986842, (524,-135), root:(589,304),
state 0x0, keycode 223 (keysym 0x0, NoSymbol), same_screen YES,
XLookupString gives 0 characters: ""
----------------------------------------------------------------
Notice that we get 2 events, one KeyPress and one KeyRelease.

The Important part of this event output is the "keycode 223 (keysym 0x0, NoSymbol)" line. By looking at this we can tell a few things. First, the key's scancode is 223. Second, there is no keysym or symbol assigned to that key.

What you need to do now is get the scancode for every extra function key on your keyboard. I suggest you pull out a pen and paper for this process because if you move the mouse or do anything else while trying to get the scancode xev will register a bunch of events that we have no interest in. So make sure to only press the key you want to get the scancode for. Also, make sure you note which button the scancode was associated with. As an example, I've included the scancodes I've gathered for my keyboard/
Key Keycode
-------------------------------------------------------
Standby 223
Mute 160
Volume Down 174
Volume Up 176
Play/Pause 162
Stop 164
Prev Track 144
Next Track 153
Email 236
Web Search 229
Run 230
Web Home 178
--------------------------------------------------------
Once Again, this is just an example! Don't use these values because your keyboard will probably be different than mine.

If you get no output from xev while trying to get your keycodes that probably means you can't use your keyboard with XFree86 4.0. Some keyboards might produce weird keycodes that X can't understand.

Giving a Name to your New Keys

Now that you've gathered all your keycodes, we have to give each one a name in order to assign keysums. This is done in the ~/.Xmodmap file. That's /home/username/.Xmodmap. If this file does not exist just create it with your favorite text editor.

You have to put a line for each key in the format "keycode XXX = keyname". I will list the content of of my .Xmodap file as an example. ~/.Xmodmap Content:
-------------------------------------------------------
keycode 223 = LStandby
keycode 160 = LMute
keycode 174 = LVoldown
keycode 176 = LVolup
keycode 162 = LPlaypause
keycode 164 = LStop
keycode 144 = LRew
keycode 153 = LFwd
keycode 236 = LMail
keycode 229 = LFind
keycode 230 = LRun
keycode 178 = LWeb
------------------------------------------------------
The name you give your keys can be whatever you wish, I suggest giving then a descriptive name in order to avoid confusion. The L prefix in my example stands for "Logitech" and is just there for my reference. Name your keys whatever name makes you happy.

Finally Assign Keysysms to the Keys

For the final configuration, we need to assign keysyms to the keys in order to use them with X. This is done in the XKeysymDB file, located in /usr/X11R6/lib/X11/XKeysymDB on a default installation of XFree86 4.0. You must be root to edit this file.

Once again, you must have a line for each key in the format: "Key Name :keysym". The key name is the name you've given your keys in the previous step, and the keysym is a unique number we will assign your keys. If you look at previous keys defined in the file you will notice a hexadecimal numbers assigned to the keys. These numbers must be unique to each key so make sure that no other key previously defined in the XKeysymDB matches the keysyms you assign. On my system I've chosen to assign keysyms in the range 10090000 to 1009000B since they were unique to my configuration.

Here's my additional entries in the XKeysymDB file for my keyboard: -------------------------------------------------------
! (comments start with a "!")
! Logitech iTouch Keyboard
LStandby :10090000
LWeb :10090001
LMail :10090002
LFind :10090003
LRun :10090004
LMute :10090005
LVoldown :10090006
LVolup :10090007
LPlaypause :10090008
LStop :10090009
LRew :1009000A
LFwd :1009000B
------------------------------------------------------ Once done, save that file and restart X. Start xev once again to verify your setup. Now if you follow the instructions in the first step again to get the scancodes of your keys, you'll notice that there is now a keysym and Symbol assigned to your key. If that was successful, you can now assign those keys to shortcuts or to launch programs. This is done differently with every window manager, so I won't go trough the process; check your window manager's documentation on how to assign shortcut keys.

I hope this was helpful to a few people, this was yet another weekend hack I did when I bought my Logitech keyboard, so success may vary on other keyboards. Please feel free to comment about the article, or send information if this procedure did not work for your keyboard model or XFree86 version.

Josh is your average UNIX hacker. Hobbyist Programmer in C, Perl and PHP. He likes to play with things to learn how they work and share his experience with others. bjosh@xxxxxxxxxxxx

 Your Comments 

Some more hints on this - 2001-02-24 02:25:19
First of all, you can skip the editing of XKeysymDB, if you just assign the keys to F13-F24. It also has the big advantage in multi OS environments that it will work with other X implementations.

To get this working in KDE 2, you need to use the menueditor. Make a directory under the system directory and make a file for each key. These files can be assigned a hotkey and a command to run. If you run KDE 2, you should use dcop for this. For example, here is the command to run with the play button: "dcop kscd default play". Unfortunately this won't work unless kscd is already running, so you should start it yourself the first time, and then you can control it with the keys. Or write a simple bash script that checks if it's running or not, and start it if necessary.

Feel free to ask me if you have problems with this on bo at suse dot de.

Bo.

Bo Thorsen ()
Reply to Comment (Replies: 0)

Gateway - 2001-02-23 23:14:28
Unfortunately, my Gateway PC's keyboard sends a series of signals. So when I hit the 'Pause' button at the top I get ctrl-meta1-alt-p or something.

Also, I found jwz's xkeycaps utility to be very useful. Still can't use my keys as I want to, but I did get it to find out what was going on in a much easier fashion than xev...

satai ()
Reply to Comment (Replies: 0)

X already has quite a few... - 2001-02-23 18:03:54
This can done also by using the files in /usr/X11R6/lib/X11/xkb/symbols. For example, the Logitech iTouch is in the inet file. This can be loaded with

setxkbmap file section

where file is the file in the above directory, and section is the type of keyboard you have. This will then give you symbols such as XF86Mail, which can the be mapped in the window manager. One problem with this is that KDE 2 doesn't like these.

Another way to do this is using hotkeys (do a search of freshmeat). Along with libosd (find from the hotkeys homepage). This will work independently of the window manager.

pbkg ()
Reply to Comment (Replies: 0)

YEAH. Finaly a use for those in unused buttons. - 2001-02-23 14:26:23
Having had a (ack cough) M$ internet pro keyboard since they came out, it will be nice to finaly make use of the top row of buttons. Previously only usable under windows (cough). Thank you for an excellent article.

THANK YOU!! but one question :) - 2001-02-23 14:20:28
Hey, Thanks SOOO Much for writing that! I know there was a way to get my keyboard shortcuts working but never took the time to figure it out! But I have 1 question...Has anyone done this and tried to bind the keys to KDE 2.0.1?? When I go to bind them in the control center it comes up as "unknown" so then when i go to bind the next key it also comes up as "unknown" and says i cant have 2 unknowns. So right now I can only have one of the keys work at a time. I know there has to be a way around this! Thanks For The Help!!

Bakiller ()
Reply to Comment (Replies: 0)

How to turn (insert key here) into modifier keys? - 2001-02-23 14:19:05
The above examples does not cover things like windoze and mouse menu keys. How do I do it? BTW, are there any (pending) standards for these additional key assignments?

Anonymous ()
Reply to Comment (Replies: 0)

....but not on Linux/PPC - 2001-02-23 12:54:10
I've been trying to do this for ages, but on my system (2.2.18pre21 on Debian 2.2, iMac Rev. B) the kernel throws away the keys and logs thir press with a message like

keyboard.c: can't emulate rawmode for keycode 113

Can I fix this so I can write/get a program that assigns these keys to actions on the console (I'd like to control the volume without aumix, mainly...:-) ) BTW, I'm thinkin' that this problem lies in the mac-keyboard driver (since that's the only place where the outputted text exists :-).



Hey, thanks for your help. :-)

--Jon

Wasted windows keys - 2001-02-23 11:15:35
I wonder how we could use the "wasted" Windows keys. I call them wasted because Linux doesn't seem to use them in any way. As you know, you can switch virtual terminal screens by pressing "ALT-F2", "ALT-F3" or whatever... BUT, when you have X running, you need to press "CTRL-ALT-F2"... I wish we could use the "Windoz" keys to switch screens without having to press "CTRL-ALT" whatever. Just press "WIN-2", or "WIN-3" ANYTIME, character mode or graphics mode to switch to a different screen. If I knew how to do it, I would.

smx ()
Reply to Comment (Replies: 2)


Please share a comment:

You are posting anonymously. Create an account.

Name (optional):

Subject:

Comment:

Allowed tags in comment body: B BR I P U

convert newlines to <BR> tags

Please note that comments are moderated. This is done by a volunteer staff. In other words, not all comments will actually be posted here. All of your comments are appreciated though, so please contribute a comment and we will try to post as many as possible.

Please also note that your comment may be displayed alongside your name, email address and url, as supplied on your account details.

 

 OSDN 

[ O|S|D|N Technology Month: Kernel 2.4 ]
Featuring:
> Live! Events <
> Weekly features! <
> Featured HOWTOs <
> Tune-up tips! <

discover more ]

 User Account 

username:

password:

Create Login

Maintenance

 Related Links 

GNOME
Interview
KDE
Chinese
Brazil
X
NAT
LinuxWorld
How To
Helix

 

User Friendly, the comic strip

 Community Ad 

Project Magnus. The Revolution is Tiled.

advertise ]

©1999, 2000 Linux.com. Legal statement :: Advertising Info

 

Google