i am a bit desperate here, and sort of disenchanted about the possibilities of defining keyboard layouts in linux (ubuntu 10.04 here). there does not seem to be any easy, graphical way to define keyboard mappings (except for keyboardlayouteditor, but frankly, i do not understand the installation description. install antlr? cairo? pango? gobject?? generate grammars?? wtf???).

i am using an apple aluminum keyboard with a german layout, but no matter what i do the (<>) and (^°) keys are always swapped (i did manage to change the default behavior for the f1...f12 keys from multimedia back to 'ordinary', application-centric... all you have to do is add the line echo 2 > /sys/module/hid_apple/parameters/fnmode to /etc/rc.local... this is so bloody obvious i am ashamed i had to search the web for this!).

adding to my distress, i find the chinese IMEs a horror (not a single one of the many i tried does anywhere come near google pinyin for windows), and have gotten neither ibus nor scime to work in a satisfactory way for me.

i find linux keyboard handling a morass. i know this must be one of the hardest problems in computer science, since this subject gets so convoluted no matter whether its on windows or in-the-browser javascript. as a linguist i am well aware of the inherent complications proper text handling poses, but looking at descriptions how to configure xkb makes building interstellar spaceships look like a cakewalk.

so my idea is as follows:

  1. find a place in the system where keystrokes are recorded;
  2. read out those codes (could be scan codes or character codes) using a daemon (implemented in python; i heard you have to listen to IOCTL or somesuch);
  3. when certain code combinations appear, switch them to do what you want;
  4. applications now get to see a X where formerly the got to see a U and vice versa;
  5. profit!

so, questions are:

  • Is there a place, in ubuntu / linux systems that does allow reading out keyboard codes?
  • Is there a way to block processing of such keyboard actions until an intercepting daemon has processed them?
  • Could i actually mess with such codes?
  • Would such an interceptor work for a broad range of use cases? like on the command line, in a gtk app, in wine, in firefox and so on?
  • An alternative would actually be to grok keyboardlayouteditor, so if someone could post about a readable, complete installation instruction or point out installable packages, that'd be great, too. or any kind of usable software.

migrated from stackoverflow.com Jun 21 '10 at 8:01

This question came from our site for professional and enthusiast programmers.

  • -1: No need to swear. – Troubadour Jun 20 '10 at 10:06
  • This is not only a Python problem. Those keys are also switched in e.g. VirtualBox running Windows. So I guess it is a more fundamental problem. – Felix Jun 20 '10 at 10:08
  • @troubadour there appears to be a need when all you want is getting things done. what part of my rant earned me a minus one? @felix the switched keys are definitely not a python problem, you are quite right. i am looking for a solution that lets me incrementally fix shortcomings, preferrably w/out the need to do arcane situps close to the linux kernel. this is one of the cases where an 'end-of-pipe' solution, as it were, looks more attractive. i am basically open for any kind of solution that needs no more than apt-get install plus say editing an understandable mapping file. – flow Jun 20 '10 at 10:21

You can read out keycodes with xev and you can map keycodes with xmodmap.

For instance if you want to map keycode 191 to F13 you could add following to your .Xmodmap file:

keycode 191 = F13

run xmodmap ~/.Xmodmap and now this button with keycode 191 should be mapped to F13 or whatever you mapped it to.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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