28

I have got new earphones, the AKG K318's to be exact and they have one of those remotes. On a smartphone, such as an Android phone or iPhone, the buttons map to actions on the music player such as play/pause, volume up/down, skip, previous, you get the idea.

I was wondering how I could replicate the same function on my computer.

I imagine the process consists of getting X to recognize the input, and then somehow mapping those inputs for an application to use.

The "device" (which would connect via sound jack) isn't listed in xinput, nor do the buttons trigger regular keyboard events.

How can I use the earphones plugged in the output sound jack as X key inputs?

3
  • 1
    Is the accepted answer ("can't be done") still correct, 3 years on? My Bose headphones come with different cables for iPhone and for Android (specifically Samsung); I have the Android cable, and wondering if I can get it to work with Linux. May 22, 2015 at 20:35
  • My feeling is that this is more of a feature request and the functionality is unsupported for the moment.
    – jonallard
    May 26, 2015 at 19:03

3 Answers 3

40

Those 'special' headphones or earphones which can be used on specialized devices to control media players, volume and mute usually have FOUR connections on the plug, versus the typical THREE a normal headphone output jack has.

The usual three are Left Channel, Right Channel and Ground (common), while the fourth is often set up as a multi-value resistance, each button when pressed presents a particular resistance on the fourth wire (+ ground), which the media device can sense and from that determine what function is needed. Pretty slick method of getting several buttons to work off one wire without resorting to expensive digital signal generators and stuff (all packed in that little blob on the wires!).

Four buttons might use four resistances (of any unit):

volume up:   1 ohm
volume down: 2 ohms
stop:        4 ohms
play:        8 ohms

If this looks suspiciously like a binary encoding scheme... it is!! (You're so smart!!) Using values similarly ratio'd, you can sense 16 different outputs, even handling multiple keys pressed at the same time. Taa Daa!

Old people might remember the first iPods, which had a little 4connector jack next to the audio out plug, which many devices plugged into alongside their audio plug which enabled control signals to be sent back and forth. This was phased out in favor of the (imho cooler!) fourth wire system... standard headphones will work as expected, and headphones set up to interface with the fourth wire method are accepted too.

But to answer your question (finally!!)... no, there is no 'standard' way to enable the functionality you're looking for. Bluetooth headsets would be your best solution. (mine are COOL!)

6
  • 8
    and yes, I take ALL my toys apart...
    – lornix
    Jun 30, 2012 at 8:21
  • 6
    "... even handling multiple keys pressed at the same time." Except that it doesn't follow the binary scheme at that point, e.g. pressing play and Vdown gives (8*2)/(8+2) or 1.6 ohms. Jun 30, 2012 at 9:14
  • 2
    There will be 16 different values, not necessarily in an ascending or descending value... the various values can be sensed. It's only 'binary' in the sense that it's a matrix of 4 buttons with either on/off positions. Nice to know someone is checking on me.
    – lornix
    Jun 30, 2012 at 9:23
  • 1
    Just keeping answers honest is all. Jun 30, 2012 at 9:24
  • 2
    If you're "lucky" enough to have a notebook/netbook with a combined headphone and mic jack then it might be possible to write a script that listens for the different noise patterns on the incoming mic signal that each button press produces, and react appropriately to them.
    – Poundex
    Jul 1, 2012 at 22:59
5

There is currently no standardized way to use your wired headset as input with Linux as far as i know. This means you won't be able to use your headset to control your music player - Bluetooth headsets on the other should work out of the box.

2

Not a solution for everyone, but my earphones are single buttoned. Apparently, some of those simple earphone buttons use a kind of mic signaling mechanism that checks if mic input is "high" (see this post and this post). Using audacity, I was able to verify that clicking the button generated a characterstic peak unachievable by speech (although I haven't tried screaming!). Looking around the internet, I came up with the following solution using sox's rec:

#!/usr/bin/sh

while true; do 
    rec -n stat trim 0 .5 2>&1 | awk '/^Maximum amplitude/ && $3 > 0.89' | grep -q 'M' && playerctl play-pause
done

playerctl is a program that controls media playback. The .5 in the code indicates the mic pol resolution. You can play around with this value if you want to implement double tapping. 0.89 indicates the threshold for the button being pushed. (mine is basically equal to 1 when pushed)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .