1. sblood86's Avatar
    I originally wrote this up for the Optimus S forum; recently I was looking through this forum and I noticed several people asking the same thing asked on the S forum, so I decided I would go ahead and share. - Looking for the Optimus S thread, click here

    Many people want to know how to change which buttons will wake their phone or if they can remap voice search to contacts or in the case of reborn rom users remap contacts back to voice search.

    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: see gingersnap for one click root - Thanks Drew!
    -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
    Pull the keypad file:
    Code:
    adb pull /system/usr/keylayout/thunder_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 V 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.

    It is my understanding that at least most of the older Optimus V roms were built over S sources and kernels, because of this they had the menu and home keys set backwards. This guide was done with the stock layout in mind, so if you have issues try reversing keys 102 and 139.

    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
    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 in the Optimus S thread.

    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:
    Code:
    adb push thunder_keypad.kl /system/usr/keylayout/
    Reboot your phone and enjoy.

    This method will also work with a text editor locally on your phone, provided you have given the editor root access.
    06-24-2011 12:10 AM
  2. sblood86's Avatar
    Flashable zips with keypad changes:

    Stock Keylayout

    Shell Rom Keylayout - Voice search remapped to call.

    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.
    arhtard likes this.
    06-24-2011 12:10 AM
  3. JerryScript's Avatar
    Nice write-up, thanks for posting.

    Just wanted to mention there is an app that does this, ButtonRemapper, and there is another app that will show you what each button's number is, keymapper.
    sblood86 likes this.
    06-24-2011 12:17 AM
  4. sblood86's Avatar
    Nice write-up, thanks for posting.

    Just wanted to mention there is an app that does this, ButtonRemapper, and there is another app that will show you what each button's number is, keymapper.
    You are right, and I should probably mention those somewhere; may do later after I have a chance to get the market links or similar.

    Main reason for this is for those who like to do things at a system level.
    Thank you for your feedback!
    06-24-2011 12:59 AM
  5. mmarz's Avatar
    Thanks for this! I didn't have the list of buttons. I've been doing this from the beginning because I didn't want to use an extra app. Nice writeup.
    06-24-2011 01:08 AM
  6. ohgoditsgoingtobreak's Avatar
    Thanks! I noticed one thing that aosp has is an option to bind the search key to an application of the users choice. How does it achieve this since there is no mention of initiating a script on the list of key events? Is it built-in to aosp, or gingerbread? I do see in a couple of posts scattered across the web that explain that this can be done by making said button run a script, but that's all I can find.
    06-25-2011 11:16 PM
  7. JerryScript's Avatar
    I'm not certain, but I think that's part of the CyanogenMod goodies aosp has included.
    06-25-2011 11:42 PM
  8. sblood86's Avatar
    Thanks! I noticed one thing that aosp has is an option to bind the search key to an application of the users choice. How does it achieve this since there is no mention of initiating a script on the list of key events? Is it built-in to aosp, or gingerbread? I do see in a couple of posts scattered across the web that explain that this can be done by making said button run a script, but that's all I can find.
    I'm not entirely certain to be honest; my research has lead me to believe that the files that actually control what events can be assigned are defined by the kcm.bin files found under /system/usr/keychars/
    The only problem is the kcm.bin format is from what I've been able to ascertain an undocumented format, because of that I have no idea how to even get them to a point that I can read the code.

    It may be possible to map it to a script of some sort which you could than change as you said, as for how to accomplish that particular mapping I am not certain.

    ---
    Post 2 has been updated to hold the flashable zips for keypad changes, sorry it took so long I wanted to redo them with edify instead of amend scripts to make them gingerbread/cm7 friendly.

    Remember these are done with the V kernel in mind so the mapping for home and menu is stock. If you are running an older rom using an optimus S kernel you will likely need to reverse the home and menu keys (basically the .kz files are identical for both phones, the change from home to menu is defined in the kernel itself).
    06-26-2011 12:32 AM
  9. ohgoditsgoingtobreak's Avatar
    I'm not entirely certain to be honest; my research has lead me to believe that the files that actually control what events can be assigned are defined by the kcm.bin files found under /system/usr/keychars/
    The only problem is the kcm.bin format is from what I've been able to ascertain an undocumented format, because of that I have no idea how to even get them to a point that I can read the code.

    It may be possible to map it to a script of some sort which you could than change as you said, as for how to accomplish that particular mapping I am not certain.

    ---
    Post 2 has been updated to hold the flashable zips for keypad changes, sorry it took so long I wanted to redo them with edify instead of amend scripts to make them gingerbread/cm7 friendly.

    Remember these are done with the V kernel in mind so the mapping for home and menu is stock. If you are running an older rom using an optimus S kernel you will likely need to reverse the home and menu keys (basically the .kz files are identical for both phones, the change from home to menu is defined in the kernel itself).
    Thanks for your reply, I have found almost exactly what you've just wrote in several places, and I overlooked it all because it didn't seem to pertain to the topic, but I guess it did afterall. Hats off to AOSP, they've done something Nobody else seems to be able to (easily) do...
    Thanks for making this thread and the zips to match, I'm actually using one of them now, as I could not seem to get the edited file to push... blah...
    06-26-2011 02:20 AM
  10. overthinkingme's Avatar
    The app LaunchKey lets you bind the app of your choice to long press search.

    Sent from my VM670 using Tapatalk
    06-26-2011 02:25 AM
  11. mmarz's Avatar
    One note, you forget to mention in your instructions that you need to mount /system as rw. The last step should be:

    Code:
    adb remount
    adb push thunder_keypad.kl /system/usr/keylayout/
    adb shell reboot
    06-26-2011 10:33 AM
  12. sblood86's Avatar
    One note, you forget to mention in your instructions that you need to mount /system as rw. The last step should be:

    Code:
    adb remount
    adb push thunder_keypad.kl /system/usr/keylayout/
    adb shell reboot
    In my experience adb will start the server for you automatically if it hasn't been running, so this should really only be necessary if the computer has been rebooted during the process, updating the OP anyway, thanks again for the feedback.

    The reason I recommend rebooting from the phone instead of initiating a reboot from adb is actually quite simple; anytime I have rebooted from adb I get an unclean shutdown. Because of that I highly recommend calling the reboot from the device itself after the files have been pushed.
    06-26-2011 11:27 AM
  13. d-fitzpatrick's Avatar
    bumping in case anyone else is looking for this information

    also found in the tips and tricks Wiki http://optimusv.wikispaces.com/Tips+and+Tricks
    Dannemand likes this.
    01-28-2012 09:43 PM
LINK TO POST COPIED TO CLIPBOARD