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

Search This thread

CarbonKang

Senior Member
Apr 6, 2010
630
1
Thanks man. Sorry my phone hates me and i couldn't do it my self. But seriously thanks! :)
 

Decad3nce

Retired Forum Mod / Inactive Recognized Developer
Feb 19, 2010
2,086
2,762
Any luck on custom app launching?

Aside from possibly spoofing the called intent by renaming the .apk(I don't think it calls the apk), I haven't found out another way... I'll go poke around the source and see how the intent>activity is handled.

Then again, I've been spacing off on this heh. damn hangover.
 

chaser841

New member
Mar 19, 2010
3
0
Is there anyway to turn the search key into like a mute button for when the phone goes off? Ideally I was looking to see if I can use it to acknowledge and mute my alert from text messages.
 

Decad3nce

Retired Forum Mod / Inactive Recognized Developer
Feb 19, 2010
2,086
2,762
Is there anyway to turn the search key into like a mute button for when the phone goes off? Ideally I was looking to see if I can use it to acknowledge and mute my alert from text messages.

Hmmm, I'm fairly certain push Volume Down mutes an alert. But I'll see what I can do.
 

brokentoaster24

Senior Member
May 9, 2010
1,243
41
Kansas
hmm, i followed the directions exactly and everything seemed to work.. but the keys still do the same thing. do i need to reboot to have the changes take effect?


edit: should have read the last line of OP's first post
 
Last edited:

MapleBacon

Member
Apr 3, 2010
26
0
I changed the search key to open up the camera but it still opens up the universal search program. I followed the directions as written and rebooted the phone. Any ideas?
 

Decad3nce

Retired Forum Mod / Inactive Recognized Developer
Feb 19, 2010
2,086
2,762
I changed the search key to open up the camera but it still opens up the universal search program. I followed the directions as written and rebooted the phone. Any ideas?

It should work. Copy and paste your edit with "CODE" tags so I can see what you did.
 

Decad3nce

Retired Forum Mod / Inactive Recognized Developer
Feb 19, 2010
2,086
2,762
PHP:
key 102   HOME
key 139   MENU              WAKE_DROPPED
key 158   BACK
key 127   CAMERA		    
key 231   CALL
key 107   ENDCALL           WAKE_DROPPED
key 191   DPAD_CENTER

key 115   VOLUME_UP         WAKE
key 114   VOLUME_DOWN       WAKE

Should work.

Are you sure you pushed it back to the right place?
Code:
adb remount
adb push heroc-keypad.kl /system/usr/keylayout/heroc-keypad.kl

After you push it back, then reboot. Then long press to see if it works. it should work. lol
 
Last edited:

MapleBacon

Member
Apr 3, 2010
26
0
The first time, I just copied the file via USB and then used root explorer to paste it back into the original system folder it was in and overwrite the original. I used the cmd prompt this time to push it through, rebooted, and it works fine. I'm happy but still curious why it didn't work the other way:confused: Thanks though. I always wanted a dedicated camera button. Looking forward to any other tricks you got :)
 

kyouko

Senior Member
Mar 6, 2010
1,091
251
The first time, I just copied the file via USB and then used root explorer to paste it back into the original system folder it was in and overwrite the original. I used the cmd prompt this time to push it through, rebooted, and it works fine. I'm happy but still curious why it didn't work the other way:confused: Thanks though. I always wanted a dedicated camera button. Looking forward to any other tricks you got :)

I edited the file on the phone and replaced it using root explorer without any problem. I'm guessing you never changed the permission on the file
> All 3 on the first column under "Read" and the top one under "write/user"
 

danaff37

Senior Member
Mar 14, 2010
2,959
900
Nashville, TN
anyway to change the long press actions? I would love to change voice dial to open voice search

(once you figure out how to launch apks also... lol)

edit: I'm a moron, I didn't realize you could long press search key to voice search... haha
 
Last edited:

MapleBacon

Member
Apr 3, 2010
26
0
Is there any way to change or add the actions for long pressing a key? For example, could I have the search button open up the camera when pressed and the browser when long pressed?
 

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.