I looked at this today again and I now think, it is not possible to detect a headset button click as extension.
The solution mentioned in Stackoverflow requires a service, to receive a key event.
And as far as I know, this is not possible as extension.
What I can offer is to detect a volume change, so if you press the volume up or down button on the headset, an event could be triggered.
Taifun