There are some important gotchas with the other solutions posted here.
For one, symbol and text substitution entries only work in Cocoa apps. If you want a truly system-wide solution that works in all applications, this is not an option.
Also, apps like KeyRemap4MacBook are great, but relying on them means you have to keep the app running in the background all the time, which may not be what you want.
Custom keyboard layouts to the rescue
Luckily, remapping keys can be done in a way that will work for any type of application, and without any additional software!
Mac OS X has supported .keylayout
files since version 10.2 (Jaguar). You can create your own keyboard layout, or rather, tweak the default one you’re using right now. Simply remap a keyboard combination you never use (for me, there are plenty of those) to the ²
and ³
symbols, and that’s it.
In my custom QWERTY keyboard layout, I can simply press ⌥
+ ⇧
+ 2
to enter ²
, and ⌥
+ ⇧
+ 3
to enter ³
. (My custom AZERTY layout has these mappings, too.)
How to create a custom keyboard layout
To create new keyboard layouts or modify existing ones, I’d recommend Ukelele.app. It has an option to create a new keyboard layout based on the one that’s currently in use.
After you’ve created your custom layout, there’s no need for the application anymore — you certainly don’t need to keep it running in the background.
How to install a custom keyboard layout
- Copy the
.keylayout
file to the Keyboard Layouts
folder within ~/Library
(if you want to install it only for the current user) or /Library
(if you want to install the layout system-wide).
- Reboot (if you installed the layout system-wide), or log out and log in again (if you installed it for the current user only).
- Enable the new keyboard layout via System Preferences › Language & Text › Input Sources.
How to make a custom keyboard layout the system default
Optionally, you could make the custom keyboard layout the system default by running the Setup Assistant with root privileges. This way, it will be used for the login screen, and any new user accounts you create will default to this layout as well. Note that this can only be done for keyboard layouts in /Library/Keyboard Layouts
(i.e., layouts that have been installed system-wide).
sudo rm /var/db/.AppleSetupDone; sudo "/System/Library/CoreServices/Setup Assistant.app/Contents/MacOS/Setup Assistant"
You will have to create a new user account in order to complete the Setup Assistant — but don’t worry, you can delete the new account afterwards.
Adding a custom icon to the keyboard layout
OS X will use the following default icon for your custom keyboard layout:
This icon will show up in the preference pane, and in the “Input menu” in the menu bar.
To replace this with your own icon, create a 16×16px image, and save it in .icns
format in the same directory as the keyboard layout itself, using the same file name (only the extension differs). For example, my custom QWERTY layout is named qwerty.keylayout
, so if I wanted to use a custom icon, it’d have to be named qwerty.icns
.
I type Dvorak myself.
While I am interested in your idea, I do not believe that it is possible.
Matias makes a keyboard that is dedicated to Dvorak in hardware, for US $100. In other words it types in Dvorak when the Mac's software keyboard layout is set to U. S. You could purchase one of those.
From the company's description:
Hardwired Dvorak layout. The Matias Dvorak Keyboard gives you the
Dvorak layout, hardwired right into the keyboard. This approach has
advantages that software-based solutions can’t offer.
Software Dvorak layouts may not take effect until after you log in, so
if you need to type a password, you’re stuck typing it in QWERTY. With
the Matias Dvorak Keyboard, you’ll never have this problem.
Switchable to QWERTY on the fly. A layout selection key lets you
instantly & easily switch the layout to standard QWERTY and back, for
those times when non-Dvorak typists want to use the computer.
The keyboard is labelled with both Dvorak and QWERTY key legends, so
you can easily see which key is which.
I have not tried this model of keyboard, but I have used other Matias products.
I type in Dvorak using a standard QWERTY keyboard, setting the Mac OS and Windows to use a software Dvorak keyboard layout. The whole point of using Dvorak is to learn to type faster, and that should also include training yourself to type without looking at the keys on the keyboard. Therefore it makes no difference to me what is printed on the keycaps, as I never look at them. So any standard keyboard will work fine for me and I can do Dvorak mapping in software on Mac OS X, Windows, and Linux for that matter.
Should it be necessary to toggle between Dvorak and the standard US QWERTY layout, that can easily be done in Mac OS X by assigning a keyboard shortcut in the Language & Text pane in System Preferences.
Best Answer
You can install a custom keyboard like Dvorak Extended, an example of which is found at
http://fwvdijk.org/
Or create substitutions for the needed characters in system preferences/keyboard/text