3.5 mm headphone jack button

Hi I would like to use the button on my headphone within the code. Here is how the 4 pin headphone jack is used with the play/ pause/ accept call buttons on the headphone.
image

Does anyone know how to do this?