[GUIDE] How to Remap Hardkey Actions || Custom App Launching

Search This thread

Decad3nce

Retired Forum Mod / Inactive Recognized Developer
Feb 19, 2010
2,086
2,761
This is really a low-level type of hack, as it just requires editing a few files.
------------------------------------------------------------------------------------------

Sick of the Hero not having a designated "camera" button?

Well then, remap the damn thing.

How to:

MAKE A BACKUP OF THE FILE BEFORE PROCEEDING

Firstly, we'll need to pull the file that controls the heroc keypad which is entitled "heroc-keypad.kl" in "system/usr/keylayout".

To pull the file:
Code:
adb remount
adb pull system/usr/keylayout/heroc-keypad.kl heroc-keypad.kl

Now the file will appear in your Android SDK tools folder so you can edit it.

I recommend using Notepad++ but any kind of text editing tool will work.

Now open the file and it should look a little something like this(minus the "unuse" keys):
Code:
key 102   HOME
key 139   MENU              WAKE_DROPPED
key 158   BACK
key 127   SEARCH
key 231   CALL
key 107   ENDCALL           WAKE_DROPPED
key 191   DPAD_CENTER

key 115   VOLUME_UP         WAKE
key 114   VOLUME_DOWN       WAKE

As you can see, there are different attributes assigned to each key.

Specific application/action launchers:
Code:
HOME                     #Launches "Home"
MENU                     #Launches "Menu"
BACK                     #Takes you back to the last activity
SEARCH                   #Launches "Universal Search"
CALL                     #Launches the "Phone" activity and corresponding .apk or initiates a call
ENDCALL                  #Ends a call
CAMERA                   #Launches "Camera" activity and corresponding .apk
FOCUS                    #Initiates Auto-Focus while using the Camera
VOLUME_UP                #Self explanatory
VOLUME_DOWN              #^

And attributes saying if it should wake the phone at button push to complete the action, or if it should just complete the action without waking the screen.

Code:
WAKE                 #Completes the action without waking the screen
WAKE_DROPPED         #Wakes the phone to complete the action

NOTE: "CAMERA" can't utilize the "WAKE_DROPPED" attribute since it's an attempt to launch an activity without initializing anything else.

Anyways you can assign any of these attributes to any of the keys.
Personally, I remap the Phone button to launch the Camera, and the Search button to activate Auto-Focus:
Code:
key 231   CAMERA
key 127   FOCUS

Then when I'm using the Camera, I just hold down the "SEARCH" button to focus and push the "TALK" button to take a snapshot. :D

After you're done with your edits, you'll need to save the file properly(NO .txt files!), and then you'll have to push it back to the phone.

Code:
adb remount
adb push heroc-keypad.kl /system/usr/keylayout

Reboot your phone, and then long press the selected button to see if your edits worked!

Enjoy!

UPDATE!!!!

Code:
--------------------------------------------------------------------
key 200   MEDIA_PLAY_PAUSE    #Pauses Music
key 201   MEDIA_PLAY_PAUSE    #^
key 166   MEDIA_STOP          #Stops the media
key 163   MEDIA_NEXT          #Plays next media
key 165   MEDIA_PREVIOUS   #Plays previous media
key 168   MEDIA_REWIND       #Rewinds the media
key 208   MEDIA_FAST_FORWARD  #Fast Forwards the media

The second half is from the AVRCP.kl which controls media actions on our device. But as you can see the keys aren't correctly mapped as we don't have that many(or those key numbers) at our disposal.

What you can actually do is take these attributes and map them in heroc-keypad.kl

Code:
key 102   HOME
key 139   MENU              WAKE_DROPPED
key 158   BACK
key 127   MEDIA_PLAY_PAUSE  WAKE
key 231   CALL
key 107   ENDCALL           WAKE_DROPPED
key 191   DPAD_CENTER

key 115   VOLUME_UP         WAKE
key 114   VOLUME_DOWN       WAKE

This maps the attribute "MEDIA_PLAY_PAUSE" at the "SEARCH" key. By pushing it, you can pause media with the first push and play it with a successive push. The added attribute "WAKE" allows it to complete the action without waking the phone.

__________________________________________________________________________________________________
I want to thank Geniusdog254 for the heads up regarding not having to edit AVRCP.kl

CHECK OUT HIS FREE APP: Search2Play(Hero/Evo support!)
and
CHECK OUT HIS REMAPPING MOD FOR THE G1


Big thanks!

NOTE: You can also use Root Explorer or any other Root File Manager that has Text Editing


Custom app launching

Ok, so with some inspiration from BuglessPete's How to make script run by using hardware keys. I've devised an 'idea' as to how to custom launch an activity with keypad push.

Currently, you can launch any activity from shell by just using am.

Here's an example of launching the browser using am in the shell:

Code:
am start -a android.intent.action.MAIN -n com.android.browser/.BrowserActivity

Which results in:

Code:
Starting: Intent { act=android.intent.action.MAIN cmp=com.android.browser/.BrowserActivity }

And the program launches! :)

But if you put this into a script, even a basic linux shell script, you can call it quickly just by running the script! So in theory if you map this script to a keycode, you can call the script by a button push.

How?

Well first, before you compile the ramdisk, you need to create a service that contains the script necessary for the intent activity you are trying to accomplish.

Second, you have to add the proper keycodes in an init script of your choice:

Code:
#example
service <activity> /path/to/yourservice
oneshot
disabled
keycodes 107 127

Which maps the activity to the search button after launching the service with the endcall button

:D

This is currently just a theory as I haven't tested it out myself(busy with other things).

But if you would like to attempt it, I'd love feedback.

Quick Service Creation Tutorial: http://developerlife.com/tutorials/?p=356
 
Last edited:

feefeeboomboom

Senior Member
Jan 17, 2010
539
43
Fargo
nice

thanks man this is awesome.

im just "learning" linux. how would i set up the search button for an intent(sp) like opening the browser.apk
 

Decad3nce

Retired Forum Mod / Inactive Recognized Developer
Feb 19, 2010
2,086
2,761
thanks man this is awesome.

im just "learning" linux. how would i set up the search button for an intent(sp) like opening the browser.apk

Well "SEARCH" essentially launches the browser by linking it automatically to google search.

But, in regards to assigning it to launch a different(unlisted) activity, I'm not sure. That's something I'm actually looking into myself, and I think I'm making a little bit of head way :p.
 

Decad3nce

Retired Forum Mod / Inactive Recognized Developer
Feb 19, 2010
2,086
2,761
Haha great work [HOPE]maybe the hero development won't die[/HOPE]

As long as there are people there willing to learn, development for the Hero will never die.

[RANT]
I'll make a post in the General Section with all the bookmarked dev'ing related resources that I've found over the year. Then people can just jump in and start reading/tinkering.

What I don't like about the HeroCDMA forum is that most of the community here doesn't share much of HOW they did/do things. Hopefully that will change.

=D
[/RANT] (Please don't respond to this part, haha)
 

thatguythatdid

Senior Member
Mar 10, 2010
842
5
With your mom :) milf
almost forgot what program are you using to open the kl file? Mine always comes out in a horizontal line instead of a vertical like yours?


Edit: Nevermind wordpad does it great
 
Last edited:

chrish03

Member
Mar 31, 2010
44
1
Thanks for this, the trackball is so annoying for pictures. I made the changes just as it states to but the zoom won't work on the search button, I hold it down and it does nothing, any idea why that may be? And the search button no longer responds on the homescreen, which makes sense but why not in the camera app?
 

Decad3nce

Retired Forum Mod / Inactive Recognized Developer
Feb 19, 2010
2,086
2,761
Thanks for this, the trackball is so annoying for pictures. I made the changes just as it states to but the zoom won't work on the search button, I hold it down and it does nothing, any idea why that may be? And the search button no longer responds on the homescreen, which makes sense but why not in the camera app?

Zoom? Do you mean auto-focus?
 

CarbonKang

Senior Member
Apr 6, 2010
630
1
I want to do this but I cant get my phone to remount. I have never had a problem before.

cd c:\android-sdk-windows\tools

adb remount


doesn't remount says "no devices found"
 

Decad3nce

Retired Forum Mod / Inactive Recognized Developer
Feb 19, 2010
2,086
2,761
I want to do this but I cant get my phone to remount. I have never had a problem before.

cd c:\android-sdk-windows\tools

adb remount


doesn't remount says "no devices found"

Heh, is your phone plugged in? USB cable damaged? USB port damaged? Hole plugged? Bears?

If it's none of those, do this:

Code:
adb kill-server
adb start-server

then

Code:
adb remount

If that doesn't work, start from the top again.
 

CarbonKang

Senior Member
Apr 6, 2010
630
1
Heh, is your phone plugged in? USB cable damaged? USB port damaged? Hole plugged? Bears?

If it's none of those, do this:

Code:
adb kill-server
adb start-server

then

Code:
adb remount

If that doesn't work, start from the top again.

none of that worked. And there is nothing wrong with the ports at all. I think its Darchdroid.. It has something defective every time I use it lol.
 

CarbonKang

Senior Member
Apr 6, 2010
630
1
Can someone make a flashable zip so i can have a designated camera button as search? I want to be able to click it to take a snap shot of my phone with dro cap. :)

Thanks
 

Top Liked Posts

  • There are no posts matching your filters.
  • 10
    This is really a low-level type of hack, as it just requires editing a few files.
    ------------------------------------------------------------------------------------------

    Sick of the Hero not having a designated "camera" button?

    Well then, remap the damn thing.

    How to:

    MAKE A BACKUP OF THE FILE BEFORE PROCEEDING

    Firstly, we'll need to pull the file that controls the heroc keypad which is entitled "heroc-keypad.kl" in "system/usr/keylayout".

    To pull the file:
    Code:
    adb remount
    adb pull system/usr/keylayout/heroc-keypad.kl heroc-keypad.kl

    Now the file will appear in your Android SDK tools folder so you can edit it.

    I recommend using Notepad++ but any kind of text editing tool will work.

    Now open the file and it should look a little something like this(minus the "unuse" keys):
    Code:
    key 102   HOME
    key 139   MENU              WAKE_DROPPED
    key 158   BACK
    key 127   SEARCH
    key 231   CALL
    key 107   ENDCALL           WAKE_DROPPED
    key 191   DPAD_CENTER
    
    key 115   VOLUME_UP         WAKE
    key 114   VOLUME_DOWN       WAKE

    As you can see, there are different attributes assigned to each key.

    Specific application/action launchers:
    Code:
    HOME                     #Launches "Home"
    MENU                     #Launches "Menu"
    BACK                     #Takes you back to the last activity
    SEARCH                   #Launches "Universal Search"
    CALL                     #Launches the "Phone" activity and corresponding .apk or initiates a call
    ENDCALL                  #Ends a call
    CAMERA                   #Launches "Camera" activity and corresponding .apk
    FOCUS                    #Initiates Auto-Focus while using the Camera
    VOLUME_UP                #Self explanatory
    VOLUME_DOWN              #^

    And attributes saying if it should wake the phone at button push to complete the action, or if it should just complete the action without waking the screen.

    Code:
    WAKE                 #Completes the action without waking the screen
    WAKE_DROPPED         #Wakes the phone to complete the action

    NOTE: "CAMERA" can't utilize the "WAKE_DROPPED" attribute since it's an attempt to launch an activity without initializing anything else.

    Anyways you can assign any of these attributes to any of the keys.
    Personally, I remap the Phone button to launch the Camera, and the Search button to activate Auto-Focus:
    Code:
    key 231   CAMERA
    key 127   FOCUS

    Then when I'm using the Camera, I just hold down the "SEARCH" button to focus and push the "TALK" button to take a snapshot. :D

    After you're done with your edits, you'll need to save the file properly(NO .txt files!), and then you'll have to push it back to the phone.

    Code:
    adb remount
    adb push heroc-keypad.kl /system/usr/keylayout

    Reboot your phone, and then long press the selected button to see if your edits worked!

    Enjoy!

    UPDATE!!!!

    Code:
    --------------------------------------------------------------------
    key 200   MEDIA_PLAY_PAUSE    #Pauses Music
    key 201   MEDIA_PLAY_PAUSE    #^
    key 166   MEDIA_STOP          #Stops the media
    key 163   MEDIA_NEXT          #Plays next media
    key 165   MEDIA_PREVIOUS   #Plays previous media
    key 168   MEDIA_REWIND       #Rewinds the media
    key 208   MEDIA_FAST_FORWARD  #Fast Forwards the media

    The second half is from the AVRCP.kl which controls media actions on our device. But as you can see the keys aren't correctly mapped as we don't have that many(or those key numbers) at our disposal.

    What you can actually do is take these attributes and map them in heroc-keypad.kl

    Code:
    key 102   HOME
    key 139   MENU              WAKE_DROPPED
    key 158   BACK
    key 127   MEDIA_PLAY_PAUSE  WAKE
    key 231   CALL
    key 107   ENDCALL           WAKE_DROPPED
    key 191   DPAD_CENTER
    
    key 115   VOLUME_UP         WAKE
    key 114   VOLUME_DOWN       WAKE

    This maps the attribute "MEDIA_PLAY_PAUSE" at the "SEARCH" key. By pushing it, you can pause media with the first push and play it with a successive push. The added attribute "WAKE" allows it to complete the action without waking the phone.

    __________________________________________________________________________________________________
    I want to thank Geniusdog254 for the heads up regarding not having to edit AVRCP.kl

    CHECK OUT HIS FREE APP: Search2Play(Hero/Evo support!)
    and
    CHECK OUT HIS REMAPPING MOD FOR THE G1


    Big thanks!

    NOTE: You can also use Root Explorer or any other Root File Manager that has Text Editing


    Custom app launching

    Ok, so with some inspiration from BuglessPete's How to make script run by using hardware keys. I've devised an 'idea' as to how to custom launch an activity with keypad push.

    Currently, you can launch any activity from shell by just using am.

    Here's an example of launching the browser using am in the shell:

    Code:
    am start -a android.intent.action.MAIN -n com.android.browser/.BrowserActivity

    Which results in:

    Code:
    Starting: Intent { act=android.intent.action.MAIN cmp=com.android.browser/.BrowserActivity }

    And the program launches! :)

    But if you put this into a script, even a basic linux shell script, you can call it quickly just by running the script! So in theory if you map this script to a keycode, you can call the script by a button push.

    How?

    Well first, before you compile the ramdisk, you need to create a service that contains the script necessary for the intent activity you are trying to accomplish.

    Second, you have to add the proper keycodes in an init script of your choice:

    Code:
    #example
    service <activity> /path/to/yourservice
    oneshot
    disabled
    keycodes 107 127

    Which maps the activity to the search button after launching the service with the endcall button

    :D

    This is currently just a theory as I haven't tested it out myself(busy with other things).

    But if you would like to attempt it, I'd love feedback.

    Quick Service Creation Tutorial: http://developerlife.com/tutorials/?p=356
    1
    The script was this

    on ramdisk > init.rc
    Code:
    service screenshot /system/bin/scrnsht
       oneshot
       disabled
       keycodes 217

    217 is the search button on my device

    system/bin/scrnsht (or the name you want for it)
    Code:
    #! /system/bin/sh
    am start -a android.intent.action.SCREENSHOT -n com.cyanogenmod.screenshot/.ScreenshotActivity

    And thats it, later I missed my search button so I used combo buttons (back and power) to trigger the screenshot
    1

    Okay, it isnt too great of a solution, but it works. What you need is root access, a text editing program, and Tasker.
    I originally made the guide for the HTC One, but Id assume you can do this for any phone, just make sure that you have on-screen keys enabled so you can still navigate.

    Get your keylayout file. There are multiple ways to do this, but since all phones use different names for them, its best to just open up an app like Root Explorer and move to the file itself, and then copy and paste it.

    Edit your button IDs. After getting your .kl file, open it with a regular text editor, and find the keys that you want to change. For mine, I used the home and back keys. Locate where they are; it wont be hard as the keys have their actions next to them, and change one key to CAMERA, and the other the SEARCH.

    Map button actions in Tasker. Finally, open Tasker (turn off Beginners view in settings), and hit New > Event > Hardware > and then your button of choice. You can either select the Camera button first, or the Search button. Inside the Event screen, set the priority to Highest, and if youre editing the Camera button, check the Stop Event button. Create a new task in the profile for your button, and create a new action. After, click App > Load app, and then select which application you would like to launch on that button. Do the same thing for the Search button, but you have to long press the search button to access it, as regularly clicking it will open Google Now.