1

I run a Danish keyboard layout in Lubuntu 14.04.3. The 2 key is malfunctioning (hardware problem). I wish to replace its use by the key F2. The F2 key value (i.e., the F2 key-press event) will then cease to be available.

This way, the result I need will do as follows:

Pressed key(s) -> Resulting character

F2             ->          2
Shift + F2     ->          "
Alt + F2       ->          @

I am not adequately proficient in Ubuntu, Lubuntu and Linux in general, and despite learning a moderate, but not sufficient, amount of xmodmap, xkb, obkey and openbox, along the way, I have not been able to remap F2 as a replacement for the 2 key in Lubuntu for my keyboard. How can I do this?

1

There is more than one way to modify keymaps, but probably the easiest is to use xmodmap utility. First you need a keycode of the F2 key. To get it run xev, hit F2 and look for keycode xx line. The example output (68 is important here):

KeyPress event, serial 34, synthetic NO, window 0x2c00001,
    root 0x7e, subw 0x0, time 373092759, (154,220), root:(162,228),
    state 0x0, keycode 68 (keysym 0xffbf, F2), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyRelease event, serial 34, synthetic NO, window 0x2c00001,
    root 0x7e, subw 0x0, time 373092866, (154,220), root:(162,228),
    state 0x0, keycode 68 (keysym 0xffbf, F2), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

Now you are ready to modify behavior of this key with xmodmap, the syntax is the following:

keycode [num] = [bare key] [shift] [Mode_switch] [Mode_switch+shift] [ISO_Level3_Shift] [ISO_Level3_Shift+shift] [Mode_switch+ISO_Level3_Shift] [Mode_switch+ISO_Level3_Shift+shift]

That's the theory, in practice the last group very often doesn't do what one would expect. Your demand doesn't seem too difficult, so the following should work:

keycode 68 = 2 quotedbl at F2 at F2 F2 F2
  • Can you also provide the instructions for doing this via XKB? Thanks in advance. – Frank Jan 19 '16 at 12:00

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.