this is an amazing paper which explains how to hack Apple Keyboard Firmware. Everybody have a microprocessor/microcontroller which aims the device. Microprocessors run operations stored in some *PROM inside the device's box. Replacing the firmware means replacing what the microprocessor does, changing the computational logic.
The concept is simple, a modern Apple keyboard has about 8K of flash memory, and 256 bytes of working ram. For the intelligent, this is more than enough space to have a field day.K. Chen demonstrated the hack to S|A at Defcon today and it worked quite well. You start out by running GDB, and set a breakpoint in Apple's HIDFirmwareUpdaterTool. This tool is meant to update the firmware in human interface devices, hence the name. The tool is run, a breakpoint set, and then you simply cut and paste the new code into the firmware image in memory. That's it.