Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,806,018 Members 43,777 Now Online
XDA Developers Android and Mobile Development Forum

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

Tip us?
 
Decad3nce
Old
(Last edited by Decad3nce; 25th April 2011 at 02:02 AM.) Reason: :D
#1  
Decad3nce's Avatar
Retired Forum Moderator / Recognized Developer - OP
Thanks Meter 2,768
Posts: 2,083
Join Date: Feb 2010

 
DONATE TO ME
Default [GUIDE] How to Remap Hardkey Actions || Custom App Launching

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.

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



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
The Following 8 Users Say Thank You to Decad3nce For This Useful Post: [ Click to Expand ]
 
HeroMeng
Old
#2  
HeroMeng's Avatar
Senior Member
Thanks Meter 6
Posts: 1,132
Join Date: Jan 2010
Location: The Bowels Of Hell
Little error.. heroc_keypad.kl is in /system/usr/keylayout/heroc_keypad.kl.
EDIT: And it's heroc-keypad and not heroc_keypad.
[SIGNATURE]
Samsung Epic 4G
----------------------------------------------------------------------------------------------------------------------------
Phones
iPhone 4S (Current)
Samsung Epic 4G (Retired)
HTC Hero (Retired)
Samsung Instinct s30 (Retired)
Numerous Tracfones (Thrown in toilet on purpose)
 
Decad3nce
Old
(Last edited by Decad3nce; 6th June 2010 at 01:06 AM.)
#3  
Decad3nce's Avatar
Retired Forum Moderator / Recognized Developer - OP
Thanks Meter 2,768
Posts: 2,083
Join Date: Feb 2010

 
DONATE TO ME
Quote:
Originally Posted by HeroMeng View Post
Little error.. heroc_keypad.kl is in /system/usr/keylayout/heroc_keypad.kl.
Nice catch, lol.

Always forget something simple.

EDIT: I really need to start posting stuff while using my laptop.
 
feefeeboomboom
Old
#4  
feefeeboomboom's Avatar
Senior Member
Thanks Meter 42
Posts: 532
Join Date: Jan 2010
Location: Fargo
Default 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
DEVICE:
  • Sprint Epic 4G SPH-D700
SOFTWARE:
  • DevoidV0.3

LOL
 
Decad3nce
Old
#5  
Decad3nce's Avatar
Retired Forum Moderator / Recognized Developer - OP
Thanks Meter 2,768
Posts: 2,083
Join Date: Feb 2010

 
DONATE TO ME
Quote:
Originally Posted by feefeeboomboom View Post
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 .
 
thatguythatdid
Old
#6  
thatguythatdid's Avatar
Senior Member
Thanks Meter 5
Posts: 842
Join Date: Mar 2010
Location: With your mom :) milf
Haha great work [HOPE]maybe the hero development won't die[/HOPE]


I'm putting this in my sig if you don't mind?
 
Decad3nce
Old
#7  
Decad3nce's Avatar
Retired Forum Moderator / Recognized Developer - OP
Thanks Meter 2,768
Posts: 2,083
Join Date: Feb 2010

 
DONATE TO ME
Quote:
Originally Posted by thatguythatdid View Post
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
Old
(Last edited by thatguythatdid; 6th June 2010 at 02:44 AM.)
#8  
thatguythatdid's Avatar
Senior Member
Thanks Meter 5
Posts: 842
Join Date: Mar 2010
Location: 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
 
feefeeboomboom
Old
#9  
feefeeboomboom's Avatar
Senior Member
Thanks Meter 42
Posts: 532
Join Date: Jan 2010
Location: Fargo
notepad++ is the sh!-|-
DEVICE:
  • Sprint Epic 4G SPH-D700
SOFTWARE:
  • DevoidV0.3

LOL
 
thatguythatdid
Old
(Last edited by thatguythatdid; 6th June 2010 at 03:53 AM.)
#10  
thatguythatdid's Avatar
Senior Member
Thanks Meter 5
Posts: 842
Join Date: Mar 2010
Location: With your mom :) milf
Quote:
Originally Posted by feefeeboomboom View Post
notepad++ is the sh!-|-
I'm a dumbass. I didn't read the entire post before I asked my question and thought that nevermind. Yes notepad is the s

Tags
moderators
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Learn How to Make a Live Wallpaper all by Yourself

Stillimages can bebeautiful, but some of you prefer to see animations on your screens. … more

Google Play Services Updated to Version 6.1

In addition to Android operating system proper, Google is focusing hard on giving the developers … more

CyanogenMod 11 M10 Available for Supported Devices

Summer vacation isover for most students out there, and it’s the time to get back to … more

XDA Forums Added for the First Batch of Android One Devices!

Just yesterday, we talked about the highly anticipated launch of the first batch … more