Intercept physical buttons on headphones?

Is it possible to do some actions when the user press the physical button on headphones?
I mean VOLUME UP, VOLUME DOWN or PLAY/PAUSE