[MOD] Remap your hardware keys

sblood86

Well-known member
Apr 12, 2011
426
103
0
Visit site
I see a lot of posts of people asking how to change which buttons wake their phone or asking if they can remap voice search to contacts or in the case of reborn rom remap contacts back to voice search. (Looking for the Optimus V thread? Click here.)

I'm sure someone has posted a walk through on this somewhere but I've yet to find it; so I decided to find the answers myself.

Just to get one bit out of the way:
Myself, the devs and other users are in no way responsible for your device or data. We will not be held accountable for any damage to your device or lost data resulting from following this thread or any other.

Thread Rules:
-Your phone must be rooted before attempting to follow this guide.
If you have the ZVD baseband see gingersnap for one click root - Thanks Drew!
Otherwise if you have ZVH baseband check out How to root LS670ZVH for a great walkthrough - Thanks sfhub!
-Before doing anything remember to make a nandroid backup.
-This guide assumes you have a basic understanding of ADB, please do not post questions regarding setup of ADB in this thread
-Please do not use this thread for 'first posts' if you need to do a first post before downloading something please do so in the 'Introductions' thread.

I am still researching this matter and learning more daily, if anyone has any information to add to the following please post it and I will gladly update.

The keypad files are a text file of sorts and therefore relatively easy to edit, the easiest way is to pull the file using adb.


From your platform-tools directory (or wherever your adb is located) go ahead and mount your phone (note that if you have not been using adb on this boot of your computer it's going to start the server in a mount mode anyway so the following isn't always required)
Code:
adb remount
(By default the optimus phones do not have a remount command included, this is added sometimes with the rooting method or by flashing a rom. If the above remount command does not work, try the following)
Code:
adb kill-server
adb start server

The only real difference between the keypads in ZVD and ZVH OS versions is the file name. ZVH they added the c in thunderc instead of just having it marked as thunder_keypad other than that the only difference is a set of comments around the voice button, being comments I've decided not to add them to my example.

Pull the keypad file:
For ZVD baseband.
Code:
adb pull /system/usr/keylayout/thunder_keypad.kl
For ZVH baseband.
Code:
adb pull /system/usr/keylayout/thunderc_keypad.kl

This is a simple text document and can be edited in most text editors, I would not recommend notepad.
If you are in need of a text editor I would recommend searching for gedit or notepad++ both should be free to download and can be found with your search engine of choice.

Stock Keypad:
Code:
#
key 2     1
key 3     2
key 4     3
key 5     4
key 6     5
key 7     6
key 8     7
key 9     8
key 10    9
key 11    0
key 158   BACK              WAKE_DROPPED
key 230   HOME              WAKE
key 60    SOFT_RIGHT        WAKE
key 62    ENDCALL           WAKE_DROPPED
key 229   MENU         WAKE_DROPPED
key 59    MENU         WAKE_DROPPED
key 139   MENU              WAKE_DROPPED
key 228   POUND
key 227   STAR
key 231   CALL              WAKE_DROPPED
key 61    CALL              WAKE_DROPPED
key 232   DPAD_CENTER       WAKE_DROPPED
key 108   DPAD_DOWN         WAKE_DROPPED
key 103   DPAD_UP           WAKE_DROPPED
#key 102   ENDCALL           WAKE_DROPPED
key 102   HOME              WAKE
key 105   DPAD_LEFT         WAKE_DROPPED
key 106   DPAD_RIGHT        WAKE_DROPPED
key 115   VOLUME_UP         WAKE
key 114   VOLUME_DOWN       WAKE
key 213   DEL               WAKE_DROPPED
key 355   DEL               WAKE_DROPPED
key 212   CAMERA
key 247   FOCUS
key 217   SEARCH            WAKE_DROPPED
key 216   VOICE

key 226   HEADSETHOOK       WAKE
key 116   POWER             WAKE
key 107   ENDCALL           WAKE_DROPPED

key 16    Q
key 17    W
key 18    E
key 19    R
key 20    T
key 21    Y
key 22    U
key 23    I
key 24    O
key 25    P

key 30    A
key 31    S
key 32    D
key 33    F
key 34    G
key 35    H
key 36    J
key 37    K
key 38    L
key 14    DEL
        
key 44    Z
key 45    X
key 46    C
key 47    V
key 48    B
key 49    N
key 50    M
key 51    COMMA
key 52    PERIOD
key 28    ENTER
        
key 56    ALT_LEFT
key 42    SHIFT_LEFT
key 215   AT
key 57    SPACE
key 53    SLASH
key 127   SYM
key 100   ALT_RIGHT

key 399   GRAVE

The primary keys in question for the Optimus S are:
Code:
key 139 MENU
key 102 HOME
key 115 VOLUME_UP
key 114 VOLUME_DOWN
key 212 CAMERA
key 247 FOCUS
key 217 SEARCH
key 216 VOICE
key 116 POWER

For example if you wanted to change your camera and voice search buttons to control music like I have done you could change the following keys:
Code:
key 212   MEDIA_NEXT
key 216   MEDIA_PLAY_PAUSE

The above would change your camera button to auto change to the next track when listening to music with the stock music player (or music mod if you are on reborn) and your voice search button to play/pause.

I use the above layout for my phone, I have found on occasion I have to reload my playlist after pausing my music but other than that I have music controls without waking my screen.

For a list of more possible events to map your hardware keys check out 'KeyEvent | Android Developers'

Make sure the filter at the top is set to API level 10 (for froyo) or API level 11 (for gingerbread) and remove the KEYCODE_ from the front of the key change.

I have not tested all of these functions but I can confirm NOTIFICATION works as I have successfully mapped it to the search key using the following change:
Code:
key 217   NOTIFICATION

Interestingly enough it turns out that the key even NOTIFICATION doesn't seem to work when mapped in ZVH, at least not to search, I havn't tried it with any other key.

Key events have three possible status' for NONE, WAKE or WAKE_DROPPED.

In the case of NONE the key will do nothing while the phone is asleep.
WAKE means that when the key is pressed the phone will wake and the command will be sent to the designated app.
WAKE_DROPPED will wake the phone but the command will not be passed to the designated app.
--Thanks to Overthinkingme for finding this information in button remapper and posting in in post #7.

Once you have made any changes to your .kl file you will need to push it back to the phone (if your computer has restarted or you experience issues pushing the file try remounting the system again using the commands outlined earlier), assuming the file is still in your adb directory you can:
For ZVD baseband.
Code:
adb push thunder_keypad.kl /system/usr/keylayout/
For ZVH baseband.
Code:
adb push thunderc_keypad.kl /system/usr/keylayout/

Reboot your phone and enjoy.

This method will also work with a text editor locally on your phone: remapped my search key earlier in a failed attempt to figure something out.
On the plus side I can confirm local text editors do work :D
 
Last edited:

sblood86

Well-known member
Apr 12, 2011
426
103
0
Visit site
Flashable zips with keypad changes:

Stock Keylayout

Shell Rom Keylayout - Voice search remapped to call.

Standard Reborn Keylayout - No wake on front buttons, voice search remapped to call

Music Controls - No wake on front buttons, voice search has been mapped to play/pause (long press with screen awake to launch music app), camera is changed to media skip.

Thanks to Nick for both the Shell and Reborn Keymaps.

Updated all zips to use Edify scripts, should be CM7/Gingerbread friendly now, let me know if there are any issues.

The above listed zips have not been updated to accommodate the new ZVH changes. I will update them when able.
 
Last edited:

sblood86

Well-known member
Apr 12, 2011
426
103
0
Visit site
Forgive my old age but whats the difference in Wake and Wake_Dropped?

That's a good question, still trying to work it out entirely but as far as I can tell wake is for a full wake and wake dropped is for the partial wake, like if the screen has just gone out but the phone has not gone to sleep yet.

I haven't tested that in full but that is my theory at least, if someone could confirm that I would update the OP.

Sorry for my lack of certainty still learning myself

Edit: Main problem with that theory is the volume keys use wake but to not wake the screen.

Edit 2: Mind if I ask what you are trying to do specifically I may be able to help further.
 

overthinkingme

Well-known member
Feb 10, 2011
219
14
0
Visit site
Button remapper explains it

Any way we can map the voice button to something useful like an app? I know I can map it to search but binding something to one search button will bind it for both..

Sent from my VM670 using Tapatalk
 

sblood86

Well-known member
Apr 12, 2011
426
103
0
Visit site
Button remapper explains it

Any way we can map the voice button to something useful like an app? I know I can map it to search but binding something to one search button will bind it for both..

Sent from my VM670 using Tapatalk

I'll give you the info that I have but again I havn't been able to fully figure this part out either. As near as I can tell the standard key events don't support mapping to things that are not predefined. If my research is correct this can be changed by somehow editing the .kcm.bin files found under keychars, unfortunatey this appears to be an undocumented format and every method I've tried to edit these has not worked. I am still working on this matter as well, I will of course update if/when I figure this out.

Edit: Updated the OP with that information for easy reference, thanks again.
 
Last edited:

overthinkingme

Well-known member
Feb 10, 2011
219
14
0
Visit site
I'm going to read up on how t-mobile implemented their "genius" button but I believe it might just be like our voice button, unfortunately.

Looking forward to developments :D

Sent from my VM670 using Tapatalk
 

Masterjakeway

Well-known member
May 26, 2011
159
10
0
Visit site
So, along the media play lines...
Can I map the menu as previous, back as play/pause, and search as next. Only when sleeping? I have successfully changed home to wake already.

thanks for any input...
 

sblood86

Well-known member
Apr 12, 2011
426
103
0
Visit site
So, along the media play lines...
Can I map the menu as previous, back as play/pause, and search as next. Only when sleeping? I have successfully changed home to wake already.

thanks for any input...

Unfortunately any changing of the keys from screen wake to screen off would require a major work around not apply-able simply with an edit in the .kl files. Would require an app of some sort to change the mapping on the fly when the screen is woken and vice versa. Anything done in the kl files requires a reboot. In short, it's all or nothing when you change it here.

You could look into button remapper, and I beleive there are a few others that have been mentioned on this thread, if not they are on the V version of the same thread, linked in the OP. One of them may do what you are wanting otherwise it's beyond my current abilities and very much beyond a simple edit of a single file.
 

basketthis

Well-known member
Nov 22, 2010
1,470
473
0
Visit site
My power button running the cm7 port is causing me to hang up on people when in a call. Lol. Anyway to make it behave like in reborn rom? It will cause the screen to blackout instead of hang up the call?
 

sblood86

Well-known member
Apr 12, 2011
426
103
0
Visit site
My power button running the cm7 port is causing me to hang up on people when in a call. Lol. Anyway to make it behave like in reborn rom? It will cause the screen to blackout instead of hang up the call?

Hmm I think there's a setting in CM7 to apply that specific option so you may want to make sure you havn't enabled that in the rom. However having taken a look at the .kl file from the Ath3nos rom which is actually Zefie's old .kl file I notice one thing that's a little odd

key 107 POWER WAKE_DROPPED

not only do I find it odd that it's in there twice but if you check the stock keylayout in the OP you will see 107 is mapped to end call. Could be as simple as remapping that.

However if you are feeling lazy or just want an easy button I have tested the zips in post number 2; they do work with the Ath3nos rom; I am still using my music controls .kl file that I did (which is a slightly modified reborn keymap) otherwise there is also the .kl for stock, reborn and shell roms, you should be able to simply pick which one you want and flash it from recovery.

I know you already know this but I'm going to say it anyway: please make a nandroid before flashing any of the zips in post 2 while I have confirmed they work if you need to go back that's the easiest way ;)

PS. Sorry for the slow reply.
 
  • Like
Reactions: basketthis

kingdavidbaker

Well-known member
Jan 7, 2011
282
37
0
www.kingdavidbaker.com
Also for anyone who just wants to edit their key layout from their phone you can use an app like Root Explorer. You will have to browse to /system/usr/keylayout/thunder_keypad.kl then click the "mount as R/W" button at the top before long pressing the file and choosing "open in text editor". Then simply change the buttons you want to map and then save and exit. A backup of the original file will automatically be created.
 

sblood86

Well-known member
Apr 12, 2011
426
103
0
Visit site
Also for anyone who just wants to edit their key layout from their phone you can use an app like Root Explorer. You will have to browse to /system/usr/keylayout/thunder_keypad.kl then click the "mount as R/W" button at the top before long pressing the file and choosing "open in text editor". Then simply change the buttons you want to map and then save and exit. A backup of the original file will automatically be created.

Yep that works, used the method a few times myself. Just remember to reboot for the change to apply
 

theBIG

Well-known member
Jan 9, 2011
55
8
0
Visit site
Thank you for this very useful guide! I posted this question in the Reborn ROM discussion, but I am not certain it's related to the ROM, so I'm asking here as well.

I wanted to change the WAKE function for the hard keys on my dad's Optimus S (rooted, Reborn 2.2.4) I get how the process works after reading this thread, and am doing everything properly via adb (push, reboot, etc.) However, I can't get the Voice Search and Camera buttons to do anything--no matter what I change them to, the buttons have no function--the only thing I could do was disable Reborn's call log function mapped to the voice search key, but I can't change it to anything else. So I decided to push the stock thunder_keypad.kl to the phone--I can mod the WAKE function for the home/menu/back/search keys, but again, can't get the voice or camera buttons to function. I'd like to get them back to their native functions, and ideally, have them set to WAKE for instant access.

Can anyone tell if I'm missing something, or is it possibly a limitation of Reborn? (sorry, I can follow instructions and figure things out, but I'm not a dev/programmer.) Thanks!
 

epeereboom

Well-known member
Apr 15, 2011
62
10
0
Visit site
If you did a nandroid backup when you first flashed reborn, I would restore that to reset your buttons. Then some where in the reborn rom thread there is a wake button zip you can flash from recovery that should do what you are looking for, if I understand correctly. The zip is the third page in. Hope that is what you were looking for.
 
Last edited:

theBIG

Well-known member
Jan 9, 2011
55
8
0
Visit site
If you did a nandroid backup when you first flashed reborn, I would restore that to reset your buttons. Then some where in the reborn rom thread there is a wake button zip you can flash from recovery that should do what you are looking for, if I understand correctly. The zip is the third page in. Hope that is what you were looking for.
Thanks for your reply, epeereboom. I did find the ZIP packages to flash, but unless I'm mistaken, all those do is update the thunder_keypad.kl by flashing, whereas I did it manually via adb. Net result should be exactly the same, unless I'm wrong.

As a matter of fact, when I mentioned pushing the stock thunder_keypad.kl to the phone, I got that file from the stock rom ZIP on pg3--just extracted and pushed instead of flashing.

edit: and to clarify, hard buttons (except for the camera and voice search) are working, I just can't seem to get those two to mod (uh, or come back to life...)
 

Trending Posts

Forum statistics

Threads
942,387
Messages
6,913,839
Members
3,158,389
Latest member
johndoe11