External ISO keyboards treated as ANSI since MacBook Pro upgraded to macOS Sierra 10.12
Since I upgraded my MacBook Pro to macOS Sierra, two keys seems to have been switched around in the keyboard when I use my external keyboard.
I use the Spanish ISO layout, and the "º" and "<" keys have been swapped. The laptop's keyboard works fine. I have not fiddled with the keyboard configuration, other than changing to my regional layout and swapping modifier keys (it's a windows keyboard).
It worked flawlessly1 before the upgrade. I know very little of how to troubleshoot macOS, what should I do?
1 I just remembered that, no, it wasn't all that flawless; from time to time the keyboard would stop responding, and I'd have to unplug and plug again. Don't think it's related, but...
PD: It happens with all external Keyboards. Tried with a few. All of them where ISO, and it seems the problem is in macOS treating my ISO keyboards as ANSI; the laptop's internal keyboard is ISO though, and has no issue. I've done a clean install of Sierra, and it's still wrong.
Solution 1:
I had the same problem with my keyboard and a German layout. Although I had "German" set up as "System Preferences/Keyboard/Input Source" most of my keys had the wrong mapping. E.g. the key right to the Left Shift Key on my keyboard is "<>" instead it was mapped to "^°".
The problem was that my keyboard was setup as an ANSI-type of keyboard (used in the US). Instead it should have been set up as a ISO-type (used in most european countries).
There are several possible solutions to this mapping problem as described by Tom Gewecke on his Blog.
The fix for this is to run the Keyboard Setup Assistant again. Sometimes there is a button for "Change Keyboard Type" visible in "System Preferences/Keyboard".
If not, you can try trashing the file /Library/Preferences/com.apple.keyboardtype.plist and restarting your machine.
Another possibility may be to open Terminal and type: sudo open /System/Library/CoreServices/KeyboardSetupAssistant.app/Contents/MacOS/KeyboardSetupAssistant
When the Keyboard Setup Assistant appears again after reboot be sure to choose the right type of keyboard - ISO.
If none of that helps follow the above link to Toms post with further options.
Solution 2:
I've had to install Karabiner Elements and then change the Keyboard Type (available on the tab Virtual Keyboard) to ISO.
Update (July 2018): After installing a MacOS update (10.13.6) the problem has appeared again. However the latest version of Karabiner Elements (12.1.0) doesn't have the Keyboard Type option anymore. There is a Country Code which was set to '1' when I opened Karabiner. After messing around with this value with no success for a while, I've restarted the Mac, which has fixed the issue.