Restoring Backslash, Pipe and Curly Brackets to where it belong on Macbook with Swedish keyboard layout

I have managed to restore Backslash and Pipe to where they belong, on my Macbook Pro running Swedish keyboard layout.

—- Updates:
Update 1: It also works fine on my Macbook Air
Update 2: Karabiner is the new name of the product used here.
Update 3: Karabiner-Elements is the next available product, but it is still lacking required features.
Update 4: This sollution does not work anymore in OS X Sierra / 10.12.x. But I solved the same problem using a keyboard layout shipped with Ukelele. It’s called “Logitech – Swedish”. I might write a new post on that later on but basically you put the file in ~/Library/Keyboard Layouts/ and select it in keyboard preferences.

Update 5: Today on OS X 10.13.4 I hade to use Karabiner-Elements in combination with the “Logitech – Swedish” keyboard layout. In the following screenshot.




—– Original post follows:
My interpretation of where they belong is as on standard PC (Windows/Linux) keyboard layout.

And I’m so happy about this so I feel the need to share my findings.

Essentially what it does is the following:
– Puts the | “Pipe” to the < “Less than” key with option/alt modifier.
– Puts the \ “Backslash” to the + “Plus” key with option/alt modifier.
– Restores the replaced mappings to be reached where those keys used to.
Update 130817:
– Added curly brackets { } 
– Added todo (please comment if you implement these)

I did this using KeyRemap4MacBook and custom remap settings.

Here is how:
Download and install KeyRemap4MacBook.
– Reboot (it uses some kernel extension…)
– Notice that you have a new icon in Finder statusbar.
There is a shortcut to preferences if you click it. A square key?
– Set up a new named layout profile under the MenuBar tab It is nice to have during tests, and to fallback on.
– Activate the new layout profile it from the statusbar icon
– Go to preferences again and -> Misc & Uninstall -> Open private.xml
– Open the private.xml in a texteditor of choice
– Replace the content it with the following text:

Fix PC-like Pipe and Backslash on Swedish keyboard

__KeyToKey__ KeyCode::MINUS, VK_OPTION, KeyCode::KEY_7, VK_SHIFT | VK_OPTION

__KeyToKey__ KeyCode::KEY_7, VK_SHIFT | VK_OPTION, KeyCode::MINUS, VK_OPTION


__KeyToKey__ KeyCode::KEY_7, ModifierFlag::OPTION_R, KeyCode::KEY_8, ModifierFlag::OPTION_R | ModifierFlag::SHIFT_R

__KeyToKey__ KeyCode::KEY_8, ModifierFlag::OPTION_R | ModifierFlag::SHIFT_R, KeyCode::KEY_7, ModifierFlag::OPTION_R

__KeyToKey__ KeyCode::KEY_0, ModifierFlag::OPTION_R, KeyCode::KEY_9, ModifierFlag::OPTION_R | ModifierFlag::SHIFT_R

__KeyToKey__ KeyCode::KEY_9, ModifierFlag::OPTION_R | ModifierFlag::SHIFT_R, KeyCode::KEY_0, ModifierFlag::OPTION_R

– Now chose “Reload XML” in the preferences “Change key” tab.
– In the top a new option should appear: “Fix PC-like Pipe and Backslash…” (see name in private.xml)
– Click it.
– DONE! No need to save. Test it out.

If you need to customize yourself, refer to the documentation.

Some tips:

– set US keyboard in System preferences, switch to it using the flag-icon in statusbar, then use the Eventviewer to find the keys you are interested in remapping.
The keycodes are in hex and need to be translated into decimal before you can map them to the corresponding Keyname in (see links below).
– Use the | char to allow multiple combination keys.
– Oddly the combination-keys go after the standard key, not before.

Introduction and documentation:
(scroll around, this page shows where the private.xml is found)

Private.xml reference manual:
(at least check out this one if you want to fix something else)