Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

At some point around late 2008 to early 2009, some keycode values (apparently, for the keys that weren't on an XT keyboard) on a standard PC keyboard when running X.org under Linux changed. I don't know whether this was due to a kernel change or an X change. Debian lenny and Ubuntu 8.04 used the old assignment; Debian squeeze and Ubuntu 10.04 used the new assignment.

So I have two xmodmaprc files, one with the old keycodes and one with the new keycodes. How do I determine which one to load from my .xinitrc and .xsession?

I want my startup files to be portable with no hassle, so I want to get rid of my present dependency on the machine name (!). And I don't want to introduce a dependency on Linux distribution versions (and anyway that would be information about the client, but it's information about the server that I need). I already have information about the server at this point in my script (all the symbols listed in xrdb(1) are available as environment variables); hopefully my question reduces to “What parameters to I compare to what values?”.

Note that since I want my startup files to work on machines that I don't administer, keysym reassignments alone are no help. For example, I want to assign my favorite modifier to the Win keys, but I can't predict what keysym will be assigned when I log in. However, if there is an XKB concept I can use in place of keycodes (and is independent of any sysadmin customization, so keysyms won't do), I'm willing to switch to XKB.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

You can find out the keycode of a key through XKB, for example

xkbcomp -a -dflts -xkb $DISPLAY - | sed -ne 's/^ *<LWIN> *= *\([0-9][0-9]*\).*/\1/p'
share|improve this answer
    
xkbcomp -a -dflts -xkb $DISPLAY - | grep 'WIN>'. –  geekosaur Mar 15 '11 at 20:35
    
@geekosaur Oooh! If only you'd notified me of that comment… Yes, that is a viable solution (falling back to the older assignments in the case I log into an unusual PC that doesn't support XKB, I suppose). –  Gilles Nov 12 '11 at 23:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.