Keyboard layouts

Apple's own keyboards use a non-standard layout that doesn't play nicely with standard keyboards. When connecting a keyboard for the first time you'll be presented with the Keyboard Setup Assistant, a series of key prompts used to determine the keyboard layout (ANSI, ISO or JIS).

Input sources then control how these key presses are interpreted by macOS. Unfortunately the selected input source is global and can't be specified per-keyboard: using a PC layout will cause keys on a MacBook keyboard to be interpreted as the PC layout, and vice-versa.

Checking keyboard layout

To check the current layout, dump the contents of /Library/Preferences/com.apple.keyboardtype.plist:

$ plutil -convert xml1 -o - /Library/Preferences/com.apple.keyboardtype.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>keyboardtype</key>
  <dict>
    <key>3-1575-0</key>
    <integer>41</integer>
    <key>840-1241-0</key>
    <integer>41</integer>
  </dict>
</dict>
</plist>

If the keyboardtype key is missing, try running the assistant (or clicking the Change Keyboard Type... button at the bottom left of the Keyboard tab of the Keyboard preferences pane):

/System/Library/CoreServices/KeyboardSetupAssistant.app/Contents/MacOS/KeyboardSetupAssistant

If it exits with an error like No unknown keyboard connected - terminating, delete the plist and reboot:

sudo rm -f /Library/Preferences/com.apple.keyboardtype.plist

The assistant should appear on login.

If it still doesn't work

macOS seems to lack good support for standard PC keyboards, a peripheral that has been largely standardised since the 1980s. If you're still having trouble, you're in for a wild ride:

  • Sometimes opening System Preferences -> Keyboard -> Input Sources and just hitting modifier keys (Shift, Control, Option, Command) will make macOS remember how keyboards work. No idea why.
  • macOS sometimes detects mice with extra buttons as additional keyboards. To check whether this is the case, open System Preferences -> Keyboard -> Keyboard and look for a keyboard-that-isn't in the Select keyboard dropdown at the top of the pane. If this is the case, try the following steps:
    • Remove the keyboardtype plist referenced above.
    • Unplug your mouse and keyboard.
    • Reboot your Mac.
    • Plug in your keyboard.
    • Complete the Keyboard Setup Assistant.
    • Plug in your mouse.
    • If it appears (it sometimes doesn't, and again I have no earthly idea why), dismiss the Keyboard Setup Assistant.
    • Now verify that your input source is configured correctly.

Backlinks