[GUIDE] Take Back Your Headset Controls!

Search This thread

IAmAN00bie

Senior Member
Dec 2, 2010
629
335
REQUIREMENTS

  • ROOT ACCESS
  • SINGLE-BUTTON HEADSET
  • ANDROID 4.1+

PREFACE

TESTED ON THE NEXUS 4 RUNNING 4.2

If you often listen to music using a single-button headset (the kind that many Samsung devices tend to ship with), then you should know that Google lets you control the headset button. By default, you can:

  • Play/Pause (Single Press)
  • Skip track (Double Press)
  • Launch Voice Search (Single-click Long Press)

Pretty cool, right? So what's the deal, then?

The issue is you CANNOT customize how you want the system to respond to your button input.

  • What if you want to long press to increase volume?
  • What if you want to triple click to go to the previous track?
  • What if you want to double click and hold to decrease volume?
  • What if you want to launch an app besides Google Voice Search (I personally have bound utter! in place of Google's search!)?

Nope, too bad.

Well, there is a workaround for this.

How does it work?

In /system/usr/keylayout, two files called Generic.kl and hs_detect.kl reside where you can modify the keymapping of the HEADSETHOOK input to an alternate key that is normally found on a 3-button headset, specifically MEDIA_NEXT. Then, you can modify how the system responds to MEDIA_NEXT by using a headset control app.

TO FIX:

**NOTE: ITEMS SURROUNDED BY A BLUE BOX MEAN IT IS THE ORIGINAL VALUE WHILE ITEMS SURROUNDED BY A RED BOX MEANS IT IS THE NEW VALUE**

1) Install the Keytest App found here: https://github.com/chrisboyle/keytest/downloads

2) Once inside the app, press the headset button. On your screen, it should read as follows:

Code:
keyCode=KEYCODE_HEATSETHOOK
scanCode=226

as shown in the following picture: http://i.imgur.com/dogxm.png


3) Using a root-enabled file explorer app (I personally use Solid Explorer), go to /system/usr/keylayout and make a backup of Generic.kl and hs_detect.kl (copying them to your internal storage, for example /sdcard/headset).

4) You will modify these two files on two different lines. The folder should look like this: http://i.imgur.com/ShpCv.png


Generic.kl:
ORIGINAL: http://i.imgur.com/dzmPy.png AND http://i.imgur.com/bdRRz.png

NEW: http://i.imgur.com/ZddZT.png AND http://i.imgur.com/PPAZk.png

hs_detect.kl:
ORIGINAL: http://i.imgur.com/dVaXK.png

NEW: http://i.imgur.com/Deh9r.png NOTE: I MANUALLY ADDED THE KEY 163 LINE IN

Simple right? You are just flipping the two values essentially.

5) Save the changes. Reboot.

6) Open the Keytest app again. Press the headset button. On your screen, it should read as follows:

Code:
keyCode=KEYCODE_MEDIA_NEXT
scanCode=226

as shown in the following picture: http://i.imgur.com/2BSHM.png

7) Now all you need to do is use an app to configure the MEDIA_NEXT key to your liking.

MEDIA_NEXT is a key typically found on 3-button headsets, symbolized by the "Right" key. An app like Headset Button Controller or Headset Droid should do the trick. Both are paid apps, but there are trial versions available. If there are any free alternatives that can do the trick, let me know and I'll add it in! (I am NOT in any way affiliated with the app developers!)

LIMITATIONS
1)A ROM update will wipe/reset the files.

1a) How can you avoid this? Pretty simple, actually! Just keep a backup of Generic.kl and hs_detect.kl after you make the changes to them, and inject them into the zip file before you flash the ROM. You can also use the following script to do this which needs to be run as root, given that you have the two files backed up in /sdcard/headset

Code:
mount -o rw,remount /system

cp -f /sdcard/headset/* /system/usr/keylayout

chmod 644 /system/usr/keylayout/*

mount -o ro,remount /system


2) An actual or simulated "MEDIA_NEXT" input will now not be recognized as a MEDIA_NEXT. This will affect, for example, 3-button headsets or tasker tasks that simulate a MEDIA_NEXT input. Also: ROMs with the long-press to skip tracks will no longer skip track on holding volume-up, as this is no longer recognized as a MEDIA_NEXT input.

2a) How can you avoid this? You can instead use a different key to be replaced rather than MEDIA_NEXT, if you so desire. The work-up will be the exact same, only the values you swap will be different.


CREDITS

 
Last edited:

IAmAN00bie

Senior Member
Dec 2, 2010
629
335
Please respond to this post if it worked for you! I don't have my Nexus 4 yet, but I am absolutely positive it works on it as well! It worked for my GNexus on 4.1 and 4.2, and it has worked across many other devices as well.
 

tssphysicsboi

Senior Member
May 7, 2011
431
41
https://play.google.com/store/apps/details?id=se.jays.headsetcontrol

I used to use this app. It offered the same functionality without having to tweak any files. I have not tested on n4 though.

This tweak is meant for long press problem only opening google now. Even Jays says this

"Compatibility
- Click-and-hold actions will not work in Android 4.1+ as Google Now intercepts them."

so even if you use jays your long press should not work unless your rom has helped you change it!
 
  • Like
Reactions: IAmAN00bie

IAmAN00bie

Senior Member
Dec 2, 2010
629
335
I just received my Nexus 4 earlier today, and I saw that there were some changes done in the /system/usr/keylayout folder. I managed to fix the problem, and will update the OP with new pictures ASAP for those looking to fix the headset problem.
 

1234568

Senior Member
Nov 25, 2010
612
212
First off thanks to the OP. I can confirm that this works perfectly. Really don't understand why Google limited the click-and-hold functionality in the first place.

Despite this method working as expected, it is just tricking the Android system. Would it be possible for developers to actually remove the limitation itself from Jellybean. This would mean that you wouldn't need to inject files after each rom update etc.
 

hvdt

New member
Dec 15, 2012
1
1
I just received my Nexus 4 earlier today, and I saw that there were some changes done in the /system/usr/keylayout folder. I managed to fix the problem, and will update the OP with new pictures ASAP for those looking to fix the headset problem.

I had the same problem after the JB 4.2.1 upgrade. hs_detect.kl isn't there. The same modifications can be made to set_jack.kl (+ add the line as posted in the original).

This works just fine now!

However, I still can't launch utter (using headset button controller), since the shortcut found in utter main screen creates a shortcut to start listening on the homescreen. Every time I triple press, a shortcut is made to my homescreen.

How did you bind utter to listen?
 
  • Like
Reactions: IAmAN00bie

MattSkeet

Senior Member
Sep 9, 2010
740
125
Derby
  • Like
Reactions: IAmAN00bie

IAmAN00bie

Senior Member
Dec 2, 2010
629
335
OP these are 2 the same images, please edit as some people will get confused

---------- Post added at 09:48 PM ---------- Previous post was at 09:19 PM ----------

Ohh and also... how do you answer a call after changes? Ive tried headset Droid and Headset Button Controller and none of the settings allows me to answer call :(

Oops, didn't catch that! I'll update it when I get done with my finals today ;_;. Did you configure the Right button aka the media next button in headset droid? Remember the configuration changed when you did the mod!

Sent from my Nexus 4 using Tapatalk 2
 

MattSkeet

Senior Member
Sep 9, 2010
740
125
Derby
Oops, didn't catch that! I'll update it when I get done with my finals today ;_;. Did you configure the Right button aka the media next button in headset droid? Remember the configuration changed when you did the mod!

Sent from my Nexus 4 using Tapatalk 2

Yeah I did. Set the right button in the right way and also disabled all other buttons . I can change volume skip tracks play pause but unable to answer calls even tho it is set up

Sent from my Nexus 4 using xda premium
 

IAmAN00bie

Senior Member
Dec 2, 2010
629
335
Yeah I did. Set the right button in the right way and also disabled all other buttons . I can change volume skip tracks play pause but unable to answer calls even tho it is set up

Sent from my Nexus 4 using xda premium

I never actually used the answer calls feature, as I don't have an inline mic. I'll try to see what's up though.

Sent from my Nexus 4 using Tapatalk 2
 

IAmAN00bie

Senior Member
Dec 2, 2010
629
335
Quick update, fixed the OP links. Sorry if I caused anyone confusion. I hope somebody finds this guide useful!
 

Boogerwooger

Member
Dec 23, 2010
22
7
Hey Guys

I have a Galaxy Note 2 and followed the switching steps mentioned to switch.from the middle to right button.

However thiere is a problem that sometimes happens... the "long press" seems to over-ride the single press so that when I'm trying to click once to pause my music, a new song comes on.


The 2nd thing is that for some reason "click and hold" has no effect whats so ever (as I could have just used it instead of long click)

Curious if you guys have had these experiences.
 

IAmAN00bie

Senior Member
Dec 2, 2010
629
335
Hey Guys

I have a Galaxy Note 2 and followed the switching steps mentioned to switch.from the middle to right button.

However thiere is a problem that sometimes happens... the "long press" seems to over-ride the single press so that when I'm trying to click once to pause my music, a new song comes on.


The 2nd thing is that for some reason "click and hold" has no effect whats so ever (as I could have just used it instead of long click)

Curious if you guys have had these experiences.

What app are you using to control your clicks?
 

Top Liked Posts

  • There are no posts matching your filters.
  • 42
    REQUIREMENTS

    • ROOT ACCESS
    • SINGLE-BUTTON HEADSET
    • ANDROID 4.1+

    PREFACE

    TESTED ON THE NEXUS 4 RUNNING 4.2

    If you often listen to music using a single-button headset (the kind that many Samsung devices tend to ship with), then you should know that Google lets you control the headset button. By default, you can:

    • Play/Pause (Single Press)
    • Skip track (Double Press)
    • Launch Voice Search (Single-click Long Press)

    Pretty cool, right? So what's the deal, then?

    The issue is you CANNOT customize how you want the system to respond to your button input.

    • What if you want to long press to increase volume?
    • What if you want to triple click to go to the previous track?
    • What if you want to double click and hold to decrease volume?
    • What if you want to launch an app besides Google Voice Search (I personally have bound utter! in place of Google's search!)?

    Nope, too bad.

    Well, there is a workaround for this.

    How does it work?

    In /system/usr/keylayout, two files called Generic.kl and hs_detect.kl reside where you can modify the keymapping of the HEADSETHOOK input to an alternate key that is normally found on a 3-button headset, specifically MEDIA_NEXT. Then, you can modify how the system responds to MEDIA_NEXT by using a headset control app.

    TO FIX:

    **NOTE: ITEMS SURROUNDED BY A BLUE BOX MEAN IT IS THE ORIGINAL VALUE WHILE ITEMS SURROUNDED BY A RED BOX MEANS IT IS THE NEW VALUE**

    1) Install the Keytest App found here: https://github.com/chrisboyle/keytest/downloads

    2) Once inside the app, press the headset button. On your screen, it should read as follows:

    Code:
    keyCode=KEYCODE_HEATSETHOOK
    scanCode=226

    as shown in the following picture: http://i.imgur.com/dogxm.png


    3) Using a root-enabled file explorer app (I personally use Solid Explorer), go to /system/usr/keylayout and make a backup of Generic.kl and hs_detect.kl (copying them to your internal storage, for example /sdcard/headset).

    4) You will modify these two files on two different lines. The folder should look like this: http://i.imgur.com/ShpCv.png


    Generic.kl:
    ORIGINAL: http://i.imgur.com/dzmPy.png AND http://i.imgur.com/bdRRz.png

    NEW: http://i.imgur.com/ZddZT.png AND http://i.imgur.com/PPAZk.png

    hs_detect.kl:
    ORIGINAL: http://i.imgur.com/dVaXK.png

    NEW: http://i.imgur.com/Deh9r.png NOTE: I MANUALLY ADDED THE KEY 163 LINE IN

    Simple right? You are just flipping the two values essentially.

    5) Save the changes. Reboot.

    6) Open the Keytest app again. Press the headset button. On your screen, it should read as follows:

    Code:
    keyCode=KEYCODE_MEDIA_NEXT
    scanCode=226

    as shown in the following picture: http://i.imgur.com/2BSHM.png

    7) Now all you need to do is use an app to configure the MEDIA_NEXT key to your liking.

    MEDIA_NEXT is a key typically found on 3-button headsets, symbolized by the "Right" key. An app like Headset Button Controller or Headset Droid should do the trick. Both are paid apps, but there are trial versions available. If there are any free alternatives that can do the trick, let me know and I'll add it in! (I am NOT in any way affiliated with the app developers!)

    LIMITATIONS
    1)A ROM update will wipe/reset the files.

    1a) How can you avoid this? Pretty simple, actually! Just keep a backup of Generic.kl and hs_detect.kl after you make the changes to them, and inject them into the zip file before you flash the ROM. You can also use the following script to do this which needs to be run as root, given that you have the two files backed up in /sdcard/headset

    Code:
    mount -o rw,remount /system
    
    cp -f /sdcard/headset/* /system/usr/keylayout
    
    chmod 644 /system/usr/keylayout/*
    
    mount -o ro,remount /system


    2) An actual or simulated "MEDIA_NEXT" input will now not be recognized as a MEDIA_NEXT. This will affect, for example, 3-button headsets or tasker tasks that simulate a MEDIA_NEXT input. Also: ROMs with the long-press to skip tracks will no longer skip track on holding volume-up, as this is no longer recognized as a MEDIA_NEXT input.

    2a) How can you avoid this? You can instead use a different key to be replaced rather than MEDIA_NEXT, if you so desire. The work-up will be the exact same, only the values you swap will be different.


    CREDITS

    3
    So...

    I have this weird Android 4.0.4 ( Lenovo A789 ) and here is my problem:

    * On ANY "one button headset" that i plug, sound comes low on vocals and whenever i press the button i get the full sound. Tried with Skullcandys and Jays One Plus. Both these headsets are working correctly on iDevices and i saw them working correctly on a samsung galaxy s2.

    Ok, now i'm going to share what i've tried (my problem might be a rom issue):

    1) Followed the tutorial in the first post ( had to create hs_detect.kl as it wasn't there ). Rebooted, still no activity on the button.
    2) tried all apps described in this forum (keytest, headsetcontrol,Jays official app, headset droid, headset button controller, ). None of them detect the button being pressed and some of these apps can detect conflicts and no conflicts were found.

    The original headset got broken (button still should work, but does nothing on keytest). It has worked before to answer calls.

    Suggestions on what can i try more

    Your problem sounds like the 3,5mm-jack of your Lenovo A789 is using the OMTP-standard instead of the now more common CTIA-standard.

    The difference lies in the order in which the signals (R, L, Ground, Mic) are set on the plug of the headset (see http://talk.sonymobile.com/thread/31455), therefore you can hear the sound correctly when pressing the button. There are adapters to use OMTP-headsets on CTIA-devices and vice-versa, but I didn't try one yet (as I didn't have to), so I can't say how good they are. But if you do some research with the terms OMTP, CTIA and adaptor you should find some useful information.
    2
    So...

    I have this weird Android 4.0.4 ( Lenovo A789 ) and here is my problem:

    * On ANY "one button headset" that i plug, sound comes low on vocals and whenever i press the button i get the full sound. Tried with Skullcandys and Jays One Plus. Both these headsets are working correctly on iDevices and i saw them working correctly on a samsung galaxy s2.

    Ok, now i'm going to share what i've tried (my problem might be a rom issue):

    1) Followed the tutorial in the first post ( had to create hs_detect.kl as it wasn't there ). Rebooted, still no activity on the button.
    2) tried all apps described in this forum (keytest, headsetcontrol,Jays official app, headset droid, headset button controller, ). None of them detect the button being pressed and some of these apps can detect conflicts and no conflicts were found.

    The original headset got broken (button still should work, but does nothing on keytest). It has worked before to answer calls.

    Suggestions on what can i try more

    It says very clearly under requirements in the OP that you need Android 4.1+
    1
    Thanks for this :good: It'll help me hunting for why I can't get the headset working properly in utter! !
    1
    Edit: Extra question, the adaptor lets the mic/button work? or it justs fixes the sound?
    There a bunch of NO-INPUT adaptors and nobody bothers to say which standard they are

    Thanks again

    I got mine on ecrater website

    Fixes the sound ... On my Lenovo A789 the button worked to answer calls and pause the music but there are reports about other android phones where the button does nothing...

    If you made changes on the button configration file on the mobile phome on attempts to make it work without the adapter, you need to have those changes reverted back to default (or factory reset the phone)