7

I am running Ubuntu 16.10 on a MacbookPro and keys 49 and 94 are inverted... I resolved this problem with xmodmap, but this won't apply permanently. After some research I found xmodmap is no longuer use by Ubuntu but xkb instead. So I searched in the configuration of xkb and I found in the config file /usr/share/X11/xkb/keycodes/macintosh this lines :

xkb_keycodes "badmap" {
    <TLDE> =  94;
    <LSGT> =  49;
};

xkb_keycodes "goodmap" {
    <TLDE> =  49;
    <LSGT> =  94;
};

This is exactly my problem, this two keys are inverted. So I wondering if I can't change my layout configuration with the param badmap.


The ouput of setxkbmap -query -v 10

Setting verbose level to 10
locale is C
Trying to load rules file ./rules/evdev...
Trying to load rules file /usr/share/X11/xkb/rules/evdev...
Success.
Applied rules from evdev:
rules:      evdev
model:      pc105
layout:     fr,fr,us
variant:    mac,oss,
Trying to build keymap using the following components:
keycodes:   evdev+aliases(azerty)
types:      complete
compat:     complete
symbols:    pc+fr(mac)+fr(oss):2+us:3+inet(evdev)
geometry:   pc(pc105)
rules:      evdev
model:      pc105
layout:     fr,fr,us
variant:    mac,oss,
Zagonine
  • 253
  • 3
  • 9

2 Answers2

7

I accidentally stumbled upon this patch, which led me to the solution:

Open /etc/default/keyboard for editing and set:

XKBOPTIONS="apple:badmap"

At next reboot those keys will be switched.

0

Unfortunately, the XKBOPTIONS option doesn't work any longer on Ubuntu 24.04. These are the steps I took to fix this on my system, running Xorg and with Apple keyboard model A1644.

First make sure you have the proper layout, adjust this depending on your keyboard: Apple docs

If your keys are all setup properly, this is not needed.

Run: setxkbmap -layout us -variant mac

Then, we need to identify the two keys we want to swap.

Run: xev | grep keycode

A window opens and you get output in your terminal. Press the two keys you want to switch and close the small window with your mouse. In my case, this gave the following output:

    state 0x0, keycode 94 (keysym 0xa7, section), same_screen YES,
    state 0x0, keycode 94 (keysym 0xa7, section), same_screen YES,
    state 0x0, keycode 49 (keysym 0x60, grave), same_screen YES,
    state 0x0, keycode 49 (keysym 0x60, grave), same_screen YES

We now note the keycode (94 and 49), these are the keys that we need to switch. Let's now find the key mappings of these keys.

Run: xmodmap -pke | grep "keycode 49 \|keycode 94"

Note the two spaces behind "grep"

This is my output:

keycode  49 = grave asciitilde grave asciitilde dead_grave dead_horn dead_grave
keycode  94 = section plusminus section plusminus section plusminus section

Now we'll switch these two keys. Run:

xmodmap -e "keycode  49 = section plusminus section plusminus section plusminus section"
xmodmap -e "keycode  94 = grave asciitilde grave asciitilde dead_grave dead_horn dead_grave"

This will effectively switch the two keys. Try it out! Note that this is not persisted, we just changed the settings in the current session.

To persist, add the first command and these last commands to your ~/.profile or any other startup script.

To append to ~/.profile, run:

cat >> ~/.profile << 'EOF'

Apple keyboard configuration

setxkbmap is optional, uncomment if needed

setxkbmap -layout us -variant mac

xmodmap -e "keycode 49 = section plusminus section plusminus section plusminus section" xmodmap -e "keycode 94 = grave asciitilde grave asciitilde dead_grave dead_horn dead_grave" EOF

Hope this helps anyone!

Sam
  • 1