I have done this for many years and I'm quite happy with it:
@peternlewis : don't be too modest For replacing the behaviour of hardware keys, you need to use Keyboard Maestro.
For more information, see the wiki Searching the Forum for Answers section.