[GUIDE] Take Back Your Headset Controls! - Samsung Galaxy Nexus

REQUIREMENTS
ROOT ACCESS
SINGLE-BUTTON HEADSET
ANDROID 4.1+
PREFACE
TESTED ON THE GALAXY NEXUS ON BOTH 4.1 and 4.2!
If you often listen to music using a single-button headset (the kind that our Nexus ships 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 sec_jack.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 sec_jack.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/kK8h3.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/ZddZT.png
sec_jack.kl:
ORIGINAL: http://i.imgur.com/7Lg7T.png
NEW: http://i.imgur.com/E0Rfi.png
Simple right? You are just flipping the two values in both files.
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 sec_jack.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
Kenkiller: http://forum.xda-developers.com/showpost.php?p=32999600&postcount=38
Headset Button Controller Dev
Headset Droid Dev
Redditor muzeofmobo for the script

This does not work on JB VZW Gnex running Atom v1.38 with Klipsche S4A headphones.

t1.8matt said:
This does not work on JB VZW Gnex running Atom v1.38 with Klipsche S4A headphones.
Click to expand...
Click to collapse
Sorry for the late reply! Are you using a correct headset app to configure your MEDIA_NEXT button?

i tried both apps you listed in this thread and the klipsche app that is supposed to be used with these headphones. none of them worked.

I'm going to give this a try on Sourcery 4.5.

Related

Cut, copy, paste

Hi guys
Any idea how i can do a cut, copy and paste function during editing of my contacts info? I tried to tap and hold on the selected text but no cut, copy and paste function is made available to me. Or is there any available freeware that will allow me to do this?
It's quite difficult not knowing or having this function for shifting the text between the fields as i need to re-type them out each time.
Thanks in advance for the assistance.
That's easy... ctrl+c, ctrl+v, ctrl+x. There is a reason that I LOVE my TP2 for having a Ctrl key, I use it all of the times. Contacts and Google Maps are two areas where the right click menu doesn't appear, and the keystroke shortcuts come in quite handy!
Jason
if you have a tilt 2, theres no copy and paste on the keyboard, i still havent figured out a way to map it to FN+C or FN+X or FN+V, but i just use swype onscreen keyboard to do it =X
You may could use "VitoCopyPaste.exe" to Cut, Copy and Paste. Just Google around. I also had it on my phone once.
You can use Keyboard Controller (link below) to remap many different keys. Since the Tilt2 doesn't have a control key, I suggest remapping the FN key+C for copy and FN+V for paste. You can allow keys to directly open programs and lots more - GREAT program. I can vouch for it working very well with the Tilt2.
http://forum.xda-developers.com/showthread.php?t=554240
Enjoy!
theres no function for copy and paste on the keyboard controller, or else i would have done that already, unless someone has a solution that i dont know about
Yeah why i didn't think of that - Ctrl + X, Ctrl + C, Ctrl + V
Thanks all for the help.
Cheers!
Jon
anyone have any idea to do this for the tilt2?
if you don't have the ctrl button, the "HTC People" contacts manager seems to have left out the popup cut/copy/paste menu on tap and hold of selected text.
but if you go to the windows contacts manager, the cut/copy/paste does come up. just either go to "More" within the HTC manager, or just start up contacts manually through the program list.
i actually prefer the windows contacts manager and have disabled the HTC tab.
xredjokerx said:
theres no function for copy and paste on the keyboard controller, or else i would have done that already, unless someone has a solution that i dont know about
Click to expand...
Click to collapse
Pick a key you are unlikely to want and map it is the Ctrl key then you can use ctrl x ctrl c and ctrl v
barbo said:
You can use Keyboard Controller (link below) to remap many different keys. Since the Tilt2 doesn't have a control key, I suggest remapping the FN key+C for copy and FN+V for paste. You can allow keys to directly open programs and lots more - GREAT program. I can vouch for it working very well with the Tilt2.
http://forum.xda-developers.com/showthread.php?t=554240
Enjoy!
Click to expand...
Click to collapse
xredjokerx said:
theres no function for copy and paste on the keyboard controller, or else i would have done that already, unless someone has a solution that i dont know about
Click to expand...
Click to collapse
xredjokerx said:
anyone have any idea to do this for the tilt2?
Click to expand...
Click to collapse
Touch_Pete said:
Pick a key you are unlikely to want and map it is the Ctrl key then you can use ctrl x ctrl c and ctrl v
Click to expand...
Click to collapse
I use the Keyboard Controller on a Tilt 2 and have FN + C mapped to Ctrl -c (specifically, emulate key press, key 67 [C key], with the Ctrl box checked, send to OS). I have done similar with FN + X, & FN + V. Works great as copy, cut, & paste everywhere I have tried it.
I cant select ( highlight ) text from windows live messenger..
Also its very annoying to tap on the screen, and than select: select text, to be able to highlight and copy something.. is there anything i can do, to use it like htc kaiser... being able to select the text immediately ? without all those steps?
adoute said:
I use the Keyboard Controller on a Tilt 2 and have FN + C mapped to Ctrl -c (specifically, emulate key press, key 67 [C key], with the Ctrl box checked, send to OS). I have done similar with FN + X, & FN + V. Works great as copy, cut, & paste everywhere I have tried it.
Click to expand...
Click to collapse
This works for me, I have been doing this since I got my Tilt2.
I have Z,X,C,V,A mapped. Very useful.
ctrl key functionality w/o need for ctrl (or Fn) key
I have found that the keyboard controller program also allows you to do this without having to use Fn (or any other two key sequence). What you can do is assign a long key press for C, X, V to serve as copy, cut, paste by emulating CTRL-C, CTRL-X, CTRL-V, while assigning the short key press (click) to retain the default key functions (i.e., c, x, v).
Of course, you can expand on this. I applied this method to create a Fn-key-free keypad. For number 1, a single click is still an apostrophe, but long press is number 1. While the built-in option to double-click Fn is definitely more efficient when you have lots of numbers to enter, my sense is that a long key press is more convenient when you have just a few numbers to input.
And, this method also works for undo (i.e., control Z on your computer can be long press z on your tilt 2). Which is a beautiful thing.

[Q] Xoom and diNovo Mini - which .kl file?

I'm looking into making changes to the .kl file for the diNovo Mini so I can wake my device with a keypress (I'm lazy =P) but there are several .kl files listed (more so than on my TB) and while there are individual files for the Logitech Revue keyboard, Apple Wireless and Motorola Xoom keyboard, there is one that is simply labeled Generic.kl which is listed as "Generic key layout file for full alphabetic US English PC style external keyboards"
I am at work and don't have the diNovo here to test with, so I wondered if anyone else uses the Mini with their Xoom and if they could test to see if they can add the WAKE function to a key and see if it works for them?
I expected another file for the diNovo to have been created when it was connected but maybe it just uses the Generic file, or maybe the one for the Revue keyboard?
If you get this going would love to hear how you do it. Have a mini myself would love to use.
It uses the Generic.kl file. I used a combination of adb logcat and the KeyTest.apk programs to figure out the correct file and key codes to edit in the file to allow the Windows button to wake and unlock the xoom as well as serve as the menu button. Mapped the Home and Back functions as well.
Once I get home I can update with which keys are what and what changes specifically I made to get it to work. When I get home and grab the dinovo mini, it takes just a couple clicks on the pad to get the xoom to recognize it is connected and to start typing.
Switching applications and generally moving about on the home screen is clumsy and somewhat random, but eventually you get there. I can sometimes get the app drawer to open by using the arrow keys in conjunction with ok/enter but there is no highlighting on the icon to indicate it is selected so sometimes you'll open another app or widget instead. Meh, I can typically get into googe voice to text easily and that's all I'm concerned with =)
Any update on this? I've got a diNovo coming and with the mouse support in 3.1 this would be excellent!

Starting launcher app (firestarter) on keyboard event

I'm using a replacement launcher (Firestarter) and a 3rd party wireless keyboard /mouse (Mele F10 Deluxe) -- things are working well, but one issue is that the "home" button on the Mele acts like the "HOME" key on a QWERTY keyboard. Instead of returning to the home screen, it sends keyboard event "KEYCODE_HOME" (Constant Value: 3 - 0x00000003).
On a (rooted) AFTV2, is there a way to assign a keyboard event (in this case, "KEYCODE_HOME") to launch a particular app (in my case, firestarter) regardless of what else is open?
Alternatively, is it possible to have the keyboard event "KEYCODE_HOME" perform the system "home" event?"
Thanks in advance for your thoughts!
http://www.mobileread.com/forums/showthread.php?t=159538
Thats five minutes on google.
The way I have solved this was to remap the keyboard layout of my Macbook Air to adb commands - whenever I run a script that can only be exited by clicking a button on a prompt. I actually remapped the entire MBA's keyboard to send the corresponding keys to the Fire TV as adb keyevents.
Code:
adb shell monkey -p your.app.package.name -c android.intent.category.LAUNCHER 1
does what you want in that case (de.belu.firestarter is the package name btw).
I dont think every button press will show up in the Fire TVs logs the same way HOME does ("nice little keylogger you sell there, A."), so instead you might have to do the remapping at another point. Your keyboard itself is too dumb to even know what being scripted means - that leaves you either messing with the OS itself - or forfeiting the keyboard in favor of an Ultrabook. Which by the way - allows you to actually work, or browse the net - and still control the Fire TV in the background.
But people seem to be happy with their Bluetooth keyboards - because, single purpose = neato.
On my k900 plus keyboard it has a home button, why not Just map Firestarter to start up when you press home twice, then you just press the home button twice on your keyboard?
Hope this helped press thanks button
harlekinrains said:
http://www.mobileread.com/forums/showthread.php?t=159538
Click to expand...
Click to collapse
Thanks for the links. For anyone else using a media airmouse such as the Mele F10 (with a "home" button that does not send the same code as the amazon remote), it's very straightforward to create a custom keyboard map that makes it function like the Amazon remote:
1) For each button that you would like to remap, use Ketest App to discover its ScanCode (for example "102" is the "Home" button on the Mele F10 Deluxe).
2) Determine the Product ID and Vendor ID for your input device with "cat /proc/bus/input/devices" and create a copy of /system/usr/keylayout/Generic.kl with the name Vendor_XXXX_Product_XXXX.kl. This custom key layout file contains your new mapping (for example, I changed the entry next to "Key 102" to "HOME" instead of "MOVE_HOME").
3) Set ownership (chown system.system) and permissions (chmod 644) for your custom key layout file.
deanr1977 said:
On my k900 plus keyboard it has a home button, why not Just map Firestarter to start up when you press home twice, then you just press the home button twice on your keyboard?
Hope this helped press thanks button
Click to expand...
Click to collapse
Thanks for sharing your experience. The issue is that on the Mele F10 Deluxe (and other combo devices that aren't designed specifically for the Fire TV box), the home button does not send the same key code as the Amazon remote -- requiring that the user create a custom key map file.
harlekinrains said:
http://www.mobileread.com/forums/showthread.php?t=159538
But people seem to be happy with their Bluetooth keyboards - because, single purpose = neato.
Click to expand...
Click to collapse
Thanks! Given the cost difference (plus, portability, and the fact that it lasts longer on a charge), I can understand why people might choose a media remote instead of a script-friendly keyboard with a screen (like an Ultrabook). Fortunately, if your 3rd party remote doesn't work like the Amazon remote out-of-the-box, it is easy to create a custom keymap. Unfortunately, this still means that, by default, FireStarter has to use ADB to listen for the home key. I was hoping that if I use a different button instead of the home key on the amazon remote, I can have the OS "listen" in a simpler way (that doesn't tie up ADB), and simply have the OS launch firestarter when this button is pressed.
Bluetooth keyboards are less clunky - thats right. So portability and also price are valid arguments for them.
But - there is also a lot that you "lose" by not using an ultrabook (beside the remote which at some point becomes just an easy to use muscle memory extension).
The argument here goes as this way -
1. Screen Mirroring is a very, very, stupid idea. Let the battery powered device do all the processing, then let it encode a video feed on top of that, and then let it transfer...
2. Link sharing on the other hand is "where its at". So for the Fire TV this means, you use the Chrome Plugin "Play to Kodi", which covers youtube and a few other sources - and you also use Video Download Helper (Chrome Plugin available as well) to get any direct video link that isnt a rtmp stream and heavily segmented and a little script that launches http://www.multilinkr.com/ in your browser, then you paste the url in your clipbord into that, use the site to generate a clickable link and then use rightclick and Play to Kodi to cast the direct video link to the Kodi Box.
Which brings me to -
3. Discoverability is pretty lousy on remote based interfaces (Kodi has the best interface for it there is out there.). Its also pretty bad on phones (which is part of why more and more content becomes facebook native and why you are so dependent on content surfacing within an app "you like") or tablets. Its actually pretty excellent on laptops. So in some sense - I see the ultrabooks as the last bastion of non curated content and real discoverability out there.
Kodi with keyboard at that stage simply doesnt cut it. Also if you are more than a novice user you need a device you use to do maintenance on Kodi - so again - why not an Ultrabook...
-
Regarding your previous question - I know that the adb way of Firestarter noticing "that the Home button was pressed" depends heavily on certain lines within a log that only indicate that _that_ button is being pressed. I dont know how its dev handled the non adb implementation - you have to ask him. It is very unlikely - that you'd find the same or an equivalent "event indication" when you press a random key on a connected keyboard.
Remember that the watcher routine has to look for something occurring, and that in the case of Firestarter this preferably has to show up on non rooted devices also. In fact - that Firestarter (and its predecessor) exist is a little miracle in its own right - because Amazon could make a very small change and it would never be able to work again. In that sense its a hack - that relies on a very specific pattern showing up in something the OS is reporting and that is accessible by any app (userspace).
Its not based on a featureset, its based on a hack.

remapping k400r music key to be the true "back" button like the remote.

I have noticed I have used the escape key on the k400r keyboard as a back button. it works for some apps but not all apps. I wish to remap the music key between the left mouse button and the home key to be equivalent to the bluetooth remote "back" button. anybody have any experience with this. I found this and was wondering if it was possible.
http://forum.xda-developers.com/showthread.php?t=850464
I know I can remap in kodi with the keyboard.xml file but I'm looking to do it global and not per application.
I'm hoping to do it as a keyboard remap within the OS as opposed to loading an application running in the background.
remapping pc-lock button instead now.
escape button on keyboard is 1
back button on remote is 158
lock pc button is 125
The music button is a press and hold and is 171 I decided I'n not using that but instead using the lock-pc button after the home button which is 125.
lsusb yields the keyboard to be 046d:c52b
I modified the /system/usr/keylayout/qwerty.kl file and added "key 125 BAcK" and reboot. nothing
I did the same for Vender_046d_Product_c532.kl which is for the logitech revue keyboard and reboot. nothing
any ideas?
got it. its generic.kl and I modified "key 125 META_LEFT" to "key 125 BACK WAKE_DROPPED"
i've been so used to using the esc key I almost feel like I want to map that to "BACK WAKE_DROPPED"
note I also had the same mod in qwerty.kl and Vender_046d_Product_c532.kl if it made an impact.
SUMMARY:
ROOT REQUIRED
So Since there is no .kl file for the k400r it uses /system/usr/keylayout/generic.kl I decided to create a new .kl file with the vender/usbdevice id. I restored generic.kl from it's backup. I copied "generic.kl" to "Vender_046d_Product_c52b.kl" (this correlates to my lsusb command earlier) and performed my keymods to this file replacing "key 1 ESCAPE" with "key 1 BACK WAKE_DROPPED"
Works great! now any mods I want for this keyboard
These keyboards are so popular, why hasn't amazon even considered that we sideload apps and use one for default. now that I understand this a have a usb air motion mouse/keyboard I'm going to create a vender.kl file for and start remapping it correctly. hope this helps others with keyboard devices
oh and the way I found out the key commands was from teh keyntrack.apk at the bottom of this link.
http://forum.xda-developers.com/showthread.php?t=850464
completed
Igonre attatched file it works intermittently. follow steps below for all rooted devices
Firetv1Rooted Firetv2Rooted and FireStickRooted
tested on firetv1root_onRBOXSEPT2016 firetv2_rooted_on5.04 and firetv stick_ROOTED_on5.05
instead of copying the file below you must edit the /system/usr/keylayout/Generic.kl
first back up the file to /sdcard/Generic.kl
then change the original file in /system/usr/keylayout/Generic.kl
by changing lines "key 125 META_LEFT" to "key 125 MENU" and also change "key 171 MUSIC" to "key 171 BACK"

Q: scancode for "back" softkey?

I have a bluetooth keyboard that I use with my totally stock GS Note 10.1 2014, running lollipop. There is a key that originally did nothing but launch the Google search bar. I disabled that and now have a dead key. I'd like to remap the Andoid "back" softkey to it.
I have an app that will let me re asign scan codes, but since the key is dead, there is no scan code for it (similar to the Fn key). Since it used to launch Google search, it can be made to work, I just don't know how. And I don't know the command code for the "back" softkey.
I do have a regular back key on the keyboard which works like a regular back key....it does not work like the Android "back"....it doesn't back out and close apps or menus.
Any suggestions? does anyone know the Andoid back command or how to find it?
thanks
I suppose it should be key 158. This is based on the information in /system/usr/keylayout/Generic.kl and /system/usr/keylayout/sec_touchscreen.kl. These files contain the keymappings (at least in cyanogenmod, but I suppose it's the same in stock?), you should be able to check them out and modify them with a filemanager like ES if you're rooted (sounds like you are). You can modify settings in there, though you might want to make a backup in case you mess anything up.

Categories

Resources