Swap Z and Y on OS X

7,343

Solution 1

One option would be to save this as private.xml in KeyRemap4MacBook.

<?xml version="1.0"?>
<root>  
<item>
<name>test</name>
<identifier>private.test</identifier>
<autogen>--KeyToKey-- KeyCode::Y, KeyCode::Z</autogen>
<autogen>--KeyToKey-- KeyCode::Z, KeyCode::Y</autogen>
</item>
</root>

You could also use Ukelele to make a new keyboard layout.

  1. Select the U.S. layout and choose File > New Based on Current Input Source
  2. Change the keys
  3. Save as a bundle to /Library/Keyboard Layouts/. Keyboard layouts in the user library aren't selected by default in password dialogs. The popovers shown when holding keys don't work with normal keylayout files.
  4. Log out and back in
  5. Enable the input source in System Preferences

To apply changes to a keylayout file you have to log out and back in after for example running touch /Library/Keyboard Layouts/.

If you run Setup Assistant again (sudo rm /var/db/.AppleSetupDone; sudo /System/Library/CoreServices/Setup\ Assistant.app/Contents/MacOS/Setup Assistant), the keyboard layout you select will be used by default on the login window and guest accounts.

Solution 2

The problem can be easily solved without ANY SOFTWARE installed. It is as easy as running the following command in the Terminal:

hidutil property --set '{"UserKeyMapping": [{"HIDKeyboardModifierMappingSrc":0x70000001D, "HIDKeyboardModifierMappingDst":0x70000001C},{"HIDKeyboardModifierMappingSrc":0x70000001C, "HIDKeyboardModifierMappingDst":0x70000001D}]}'

Keep in mind that the keys are swapped on the hardware level, so if you use other keyboard layouts which have both QWERTZ and QWERTY, you might get into issues with keys being swapped in the other layout. If you use just a single layout or all your layouts are the same QWERTX type, it's not an issue at all. To revert this swap back at any point, just do the following command:

hidutil property --set '{"UserKeyMapping": [{}]}'

To make this change permanent, make sure the first command is executed after MacOS startup. One way to do that would be something like:

cat << EOF | sudo tee -a /Library/LaunchDaemons/org.custom.keyboard-remap.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>org.custom.keyboard-remap</string>
    <key>ProgramArguments</key>
    <array>
      <string>/usr/bin/hidutil</string>
      <string>property</string>
      <string>--set</string>
      <string>{"UserKeyMapping": [{"HIDKeyboardModifierMappingSrc":0x70000001D, "HIDKeyboardModifierMappingDst":0x70000001C},{"HIDKeyboardModifierMappingSrc":0x70000001C, "HIDKeyboardModifierMappingDst":0x70000001D}]}</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <false/>
  </dict>
</plist>
EOF
sudo launchctl load -w /Library/LaunchDaemons/org.custom.keyboard-remap.plist

That's all for now!

Solution 3

Oh yes, Apple must be special and make even the most trivial tasks brutally complicated.

If you are a normal person like me who doesn't want to fiddle with such a trivial task like having a normal keyboard, you can download my prebuilt files made by Ukulele. They have been built on Sierra, but should work. I am attaching a .dmg installer here. You can check the file as you should not trust blindly strangers on the net :)

Now you'll be a happy camper.

Download from zippyshare

Share:
7,343

Related videos on Youtube

user1640303
Author by

user1640303

Updated on September 18, 2022

Comments

  • user1640303
    user1640303 over 1 year

    I have MacBook Air with US keyboard and I'm quite happy with this. The only thing that bugs me is the QWERTY keyboard layout. Is there any way to change it to QWERTZ? I'm not interested in changing any other key; I only want to swap those two.

  • Martin
    Martin almost 4 years
    Yes, Apple must be special at any cost... thanks for this!