[ControllerMate][1] does this. At work I use the Microsoft Natural ergonomic keyboard and a Logitech mouse. ControllerMate has hardware profiles for both, and I have many of the MS-specific keys remapped to other functions.

Like yours, my keyboard also has an otherwise useless Mail button. With Controllermate open, if I press the Mail button while viewing the Microsoft keyboard profile, the list of available key sequences automatically jumps to the one it just received. You can then program that key to do whatever you like, even when ControllerMate isn't open.

![enter image description here][2]

  [1]: http://www.orderedbytes.com/
  [2]: https://i.sstatic.net/bj53d.png