Create custom keyboard layouts with Ukelele
Ukelele is a tool that can create XML keyboard layouts for use in OS X version 10.2 and later.
Apple provides a number of layouts for various purposes in Mac OS X--mainly for international layout differences, but also for variations such as Dvorak. Besides localization purposes, there are also times when specialized layouts may be useful for certain technical applications, to just disable a key, or to swap two modifier keys' functions on a standard keyboard layout. Regardless of the reason, people have wanted to easily edit or create new keyboard layouts in OS X, but have not been able to do so with any utilities Apple provides.
While Mac OS X has supported XML-based keyboard layouts since 10.2, editing them manually can be frustrating. The files are long and confusing, which can easily result in errors and nonfunctional layouts. Ukelele provides an intuitive graphical interface for these XML layout files, giving people an easy way to customize lettering as well as assign multiple-character strings to keys, and also create custom modifier keys.
The program has recently been updated, and should work on all versions of Mac OS X since 10.2.
Upon opening the program, it will show a full empty keyboard layout, or display a full one if you choose to open an existing layout.
From here you can edit the behavior of keys by double-clicking them with various modifier key combinations held down to change the typed character with that particular combination.
The displayed keyboard layout will then be updated, and you can continue to edit the rest of the keys, after which the layout can be saved to the /Library/Keyboard Layouts/ folder where they should then appear in the system preferences.
Ukelele can be downloaded for free from the developer's site.
Several keyboard layouts are included with Ukelele to serve as starting templates, but additional layouts can be found in the "Mac Unicode keyboard layouts" section of this Web page.