If you use an external keyboard with Home and End keys on a Mac and have previously used a Windows computer, you might have noticed that these buttons don't work as you'd expect them to. Let's fix it.

Step-by-step guide

  1. Open a Finder window.

  2. Click the Go menu in the menu bar at the top of the screen.

  3. Click Go To Folder.

  4. Type ~/Library and click Ok.

  5. Look for a folder called KeyBindings.
  6. If it does not exist, create it.
  7. Create a file named DefaultKeyBindings.dict in the KeyBindings folder with the contents below.
  8. Reboot your computer.

 

DefaultKeyBindings.dict
{
  "\UF729"  = moveToBeginningOfLine:; // home
  "\UF72B"  = moveToEndOfLine:; // end
  "$\UF729" = moveToBeginningOfLineAndModifySelection:; // shift-home
  "$\UF72B" = moveToEndOfLineAndModifySelection:; // shift-end
  "^\UF729" = moveToBeginningOfDocument:; // ctrl-home
  "^\UF72B" = moveToEndOfDocument:; // ctrl-end
  "^$\UF729" = moveToBeginningOfDocumentAndModifySelection:; // ctrl-shift-home
  "^$\UF72B" = moveToEndOfDocumentAndModifySelection:; // ctrl-shift-end
}

 

 

You can change the behavior of other keys as well!

Key Codes
Key Modifiers 
^ : Ctrl 
$ : Shift 
~ : Option (Alt) 
@ : Command (Apple) 
# : Numeric Keypad 
 
Non-Printable Key Codes 
 
Up Arrow:     \UF700        Backspace:     \U0008        F1:  \UF704 
Down Arrow:   \UF701        Tab:           \U0009        F2:  \UF705 
Left Arrow:   \UF702        Escape:        \U001B        F3:  \UF706 
Right Arrow:  \UF703        Enter:         \U000A        ... 
Insert:       \UF727        Page Up:       \UF72C 
Delete:       \UF728        Page Down:     \UF72D 
Home:         \UF729        Print Screen:  \UF72E 
End:          \UF72B        Scroll Lock:   \UF72F 
Break:        \UF732        Pause:         \UF730 
SysReq:       \UF731        Menu:          \UF735 
Help:         \UF746 

 

References