Aral Balkan

Mastodon icon RSS feed icon

Reclaiming your backtick/tilde key with a UK Macintosh key layout on an ANSI US Keyboard in GNOME

A Topre Realforce 87UW 55g ANSI US layout keyboard with white and grey keys and a Filco wooden wrist rest.

Thonk, thonk, thonk!

Let me begin by acknowledging that this is most likely a niche use case. I am documenting this for my own future reference as much as anything else. That said, the technique can be used to remap or swap or alter your keyboard’s layout to your heart’s content.

As a recent owner of a Topre Realforce 87UW 55g keyboard1 who uses UK Macintosh layout on his Linux box (🎶sosumi🎶), my one pain point is missing my beloved backtick2/tilde key: `~.

Now, of course, I hear you mutter, “but, Aral, you could just hold down your handy AltGR3 key and tap the ] key twice to create a tilde by abusing the diacritic4” Goes without saying really – but that’s no fun when you’re running a Unix-based system5 and you’re a programmer who loves template strings in JavaScript.

So, instead, here’s how to set the key marked as the `~ key on an ANSI US keyboard to actually be that key by assigning it the same values as the `~ key that falls between the Shift and Z keys on a UK Macintosh layout and which doesn’t exist on an ANSI US keyboard.

  1. Backup your current keyboard mapping6:

    xmodmap -pke > ~/xmodmap_original
  2. Find the keycodes you need by running the following command and pressing the keys you’re interested in. You are going to override the values of the key you want to set with the non-existent key (in my case, I had to press the non-existent key on my laptop’s ISO UK keyboard):

    xev -event keyboard
  3. Create a file in your home directory (e.g., called my-keyboard-customisations) with your Xmodmap setting:

    ! Make the useless section key in the Mac/UK layout
    ! into the priceless backtick-shift-tilde key.
    keycode  49 = grave asciitilde less greater bar brokenbar bar brokenbar grave asciitilde bar brokenbar backslash bar bar brokenbar
  4. Make a simple script that will run xmodmap with your customisations file (e.g., in ~/bin/modmap):

    #!/bin/sh
    xmodmap ~/my-keyboard-customisations
  5. Remember to make the script file executable:

    chmod +x ~/bin/modmap
  6. Create a GNOME Desktop file to run at startup (e.g., _~/.config/autostart/xmodmap.desktop) with the following contents:

    [Desktop Entry]
    Type=Application
    Exec=/home/{REPLACE-WITH-YOUR-ACCOUNT-NAME}/bin/modmap
    Hidden=false
    X-GNOME-Autostart-enabled=true
    Name=xmodmap
    Comment=xmodmap script

Now log out and log back in again and your new settings should take effect.

And voilà7, just like that, I have my backtick-shift-tilde key back and can enjoy my beloved UK Macintosh layout but with extra thonk-thonk-thonks! 🤓

~~~ fin ~~~

Sources


  1. Oh my goodness these keys are amazing to type on! ↩︎

  2. Alt Graph (Right Alt). ↩︎

  3. Or the accent grave, if you will. ↩︎

  4. And similarly, you can create a backtick by layering two accent grave diacritics like this:

    AltGr | | ↩︎

  5. There’s no place like ~. ↩︎

  6. You can return to your original mapping at any time using:

    xmodmap ~/xmodmap_original
    ↩︎

  7. In case you’re wondering what the accent grave diacritic is useful for, I just used it to write the a-grave in voilà:

    AltGr | a

    Of course, now that I have my backtick key back, I can use my Compose Key instead:

    Compose ` a ↩︎