Next post: A Little Parser

Using Windows keyboard shortcuts on a Macintosh computer

I’ve been using a Mac for a bit, but the keyboard shortcuts never felt quite right to me. For example, Cmd-Shift-X instead of Ctrl-Y to redo, and I missed Alt-Left to go back. Now, though, using a Mac is comfortable to me again, because I was able to change nearly all of the keybindings - even the less common ones - to the Windows ones. And with my external keyboard, with its Ctrl, Win, and Alt keys, I’m good to go!

Here’s what I did:

1) I installed the open source program Karabiner Elements.

</a>

2) I gave Karabiner all of the permissions it needed, it just takes a few cycles of opening the Karabiner Elements program, it telling me to grant a privilege in System Preferences, granting the privilege, and starting Karabiner again. If Karabiner doesn’t show up in the list, you can click + to add it manually. Also, restarting my Mac helped when the message about allowing the extension didn’t show up the way I had expected it to. 3) I opened Karabiner Elements, went to Complex modifications, on the Parameters tab, and changed simultaneous_threshold_milliseconds from 50 to 40. This makes it harder for Karabiner to mistake keypresses as simultaneous, and also makes sure a profile is initialized.

</a>

02settingmilli.png

4) I clicked on the Profiles tab and made sure that the profile name was Default. 03defaultprof.png

5) I then quit Karabiner Elements and opened a Terminal. Install Homebrew if you don’t already have it. I ran brew install yqrashawn/goku/goku to install a program called “Goku”, which makes it simpler to add custom Karabiner keyboard shortcuts. 6) In a terminal, run open -e ~/.config/karabiner/karabiner.json. This should open up a text file with Karabiner’s current configs. You can close the file without changing it. (This is the file Goku will modify). 7) In a terminal, run touch ~/.config/karabiner.edn. We’ll be writing our keyboard shortcuts into this file. Runopen -e ~/.config/karabiner.edn, and type in an example keyboard binding like this:

{
    :main
    [
        { :des "home goes to line start" :rules [[ :home :!CCleft_arrow ]] }
    ]
}

8) Save changes to the file, then go back to a terminal and run goku. 9) Reopen Karabiner Elements, and under Complex Modifications

More tweaks I made:

I can set my external keyboard on my Macbook Pro as if it were the normal keyboard, which is convenient. I used System Preferences->Accessibility->Mouse and Keyboard to Disable trackpad when external mouse is connected. Then I connected my external keyboard, and opened Karabiner Elements, and clicked on Devices->Advanced tab->Disable the builtin keyboard when one of the following selected devices is connected and checked the box for my Logitech keyboard. Now I can rest my external keyboard on the Macbook’s keyboard without accidentally pressing keys!

The shortcuts I added:

Using Ctrl-Left and Ctrl-Right to move by word.

Alternatives I considered:

Mac OS lets you change many keyboard shortcuts without even needing 3rd party software, which is a great feature. I used System Preferences to customize my shortcuts for a few days. Pros: the new shortcuts appear graphically in the menus, which is better than Karabiner which doesn’t update any menus when you change the shortkeys. You can also bind a shortcut to.a menuitem that doesn’t have a shortcut, which would be nontrivial in Karabiner. Cons: I don’t see the way to bind to actions that have a keyboard shortcut but no menuitem. For example, I often open Chrome Developer Tools, but I don’t think there’s a menuitem for it, so I don’t know of a way to change the default F12 shortcut. Most importantly, though, I don’t know of a way to export the adjustments in System Preferences, so when I move between machines or reinstall the OS, I need to click everything in again.

I also tried adjusting DefaultKeyBinding.dict. It’s a cool trick, by creating a text file at ~/Library/KeyBindings/DefaultKeyBinding.dict (the casing seems to matter), one can remap keyboard shortcuts and even create new bindings that do useful actions like insert text and act like emacs. This gist by trusktr gave me some good ideas for my bindings. Ultimately, Karabiner just has more features, and if I want my keybindings to trigger complex actions, I can use Alfred, or use Karabiner to bind a key to run AppleScript.

If you’d like, share your thoughts / most useful keyboard shortcuts as a comment below!