Back to writing
Article

US - UK Key Remap for Mac

· 2 min read · Barry Hall
US - UK Key Remap for Mac

A short post on keyboard mappings!

One thing I find with programming is that the US keyboard layout is the most common and widely used, especially with mechanical keyboards. However, I’m from the UK and use a UK layout.

Over time I’ve wanted to switch to US, so I bought an external Apple keyboard with a US layout. But I still use my MacBook Air a lot and it has a UK layout. Switching between the two is a pain, especially for the § and ` (backtick) keys - they’re swapped between layouts.

I’ve found a way to remap the keys so I can use the same layout consistently. It flips the two keys when I’m on the Air’s built-in keyboard, then flips them back when I’m on the external. A bit fiddly, but it works.

Next time I upgrade my Mac (waiting for the 2026 redesign) I’ll go straight to US layout, but for now this is a solid workaround.

Here’s what I added to my .zshrc:

key_map() {
  hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000035,"HIDKeyboardModifierMappingDst":0x700000064},{"HIDKeyboardModifierMappingSrc":0x700000064,"HIDKeyboardModifierMappingDst":0x700000035}]}'
}

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

When I’m on the Air keyboard, I run key_map. When I switch to the external, I run key_reset. Simple.

This might be overkill for some people, but for me it’s worth it. I get a consistent layout and can rely on muscle memory. Plus you learn a bit along the way!

Happy coding!