5,606,722 Members 36,705 Now Online
XDA Developers Android and Mobile Development Forum

Remapping Physical Buttons/Adding Alternate Keys

Tip us?
 
moah909
Old
(Last edited by moah909; 4th March 2012 at 07:57 PM.) Reason: Forgot to add files
#1  
Member - OP
Thanks Meter 20
Posts: 70
Join Date: Oct 2010
Location: Sekret

 
DONATE TO ME
Default Remapping Physical Buttons/Adding Alternate Keys

I am aware that there is a thread in the Droid 4 Dev Section but as I am a "New User" I can't post there
^^ And as I am a new user please excuse any mistakes I make in posting/formatting this

I am going to be redoing this guide soon for several reasons.
A few days after I made this thread the root functionality of File Expert became something you have to pay for. I also found a good hex editor which is much clearer then Notepad ++.

There are two parts to this guide, Remapping Physical Keys/Buttons and Alternate Keys(Using the SYM key as an ALT key as on previous Droid versions).

Things to download
File Expert (I use this as my root file explorer, permission editor, etc. it also lets me remount the /system as read write which I couldn't seem to do with adb remount or busybox remount.) You dont NEED this, you should theoretically be able to use terminal/adb shell but I couldn't get it to work so this guide uses it.

KeynrTracker.apk (For Remapping buttons not covered) Attached, From http://forum.xda-developers.com/showthread.php?t=850464 - the actual button remapping tool doesnt work with Droid 4 yet

Notepad++ I would recommend using Notepad++, but any editor that can handle binary/unix files - NORMAL NOTEPAD DOES NOT WORK, NOR DOES WORD

THE PHONE NEEDS TO BE ROOTED FOR THIS TO WORK - MAKE A BACKUP OF THE FILES THAT WE ARE GOING TO EDIT

Remapping Physical Keys
The files in /system/usr/keylayout are the configuration for physical buttons, you can edit all of them, but I would recommend only editing omap-keypad.kl(Physical Keyboard) for the time being, as you could disable the capacitive buttons. IF you do somehow mess up omap-keypad.kl (I didnt have the correct permissions at first) android has a default generic version it defaults on if omap-keypad.kl doesn't work correctly, you can tell it is using this as the Caps Lock key, Shift key, SYM key wont work properly and the Arrow buttons will all be rotated to the right so up = right, right = down etc.

This part of the guide is essentially this older guide for HTC Hero, but with more customization for the Droid 4.

Either download my uploaded copy of the original omap-keypad.kl or get your own from /system/usr/keylayout/omap-keypad.kl

Open omap-keypad.kl in a text editor either on your phone(touchqode is what I use) or on your computer (Notepad++)

For this example I am going to remap the SYM key to an ALT key so it can be used in the next part of this guide.

In your text editor find
Code:
key 162   SYM               WAKE_DROPPED
(It should be at the bottom) 162 is the physical scancode, SYM is the action that happens and WAKE_DROPPED tells the OS that if the phone is off pressing key 162 will wake it but it will not send the keypress. We want to make this an alt button so all we do is change SYM to ALT_LEFT (You have it be ALT_RIGHT, I'm not sure theres a difference but I use ALT_LEFT). So it should look like
Code:
key 162   ALT_LEFT               WAKE_DROPPED


If you want other keys, for example I remapped the OK key to be a SHIFT_RIGHT key, you need to find the scan code for the key using the attached KeynrTracker.apk


So in this case the scancode is 232, so we go into our omap-keypad.kl file and find key 232


We see that it is mapped to DPAD_CENTER and I want to make it a shift button so I'll change it to SHIFT_RIGHT


Now we need to get our keymap back onto the phone should be as simple as
Code:
adb remount
adb push omap-keypad /system/usr/keylayout
BUT, that did not work for me so I had to use File Expert to remount and copy the file. So transfer the file to the internal phone storage/sdcard, then use File Expert to remount the /system as rw.
Go to /system press the menu button -> More -> Mount -> Mount as Read Write


Then copy the edited file from your sdcard to /system/usr/keylayout it should prompt you that there is a file there called omap-keypad.kl, select overwrite.
Then long hold on the omap-keypad.kl file and select permissions from the menu.


Make sure the permissions look like below, and click apply.


Now reboot your phone and your custom key mappings should work!

Creating Alternate Keys
The biggest issue I have from switching from a OG Droid to the Droid 4 is the fact that you have to press SYM and select your symbol instead of alternate symbols for a key.

So we already set up the SYM key to act as an ALT key in the first part, but now we have to define the keys so they do something when our "ALT" key is pressed, this data is stored in /system/usr/keychars/omap-keypad.kcm.bin, like before you can use my uploaded versions or get your own from that directory. But unlike before these aren't straight forward text files they have been converted to binary, because it is faster for the system to read. So when we open it in Notepad ++ this is what it shows


Because this file is binary/hex the all the nul symbols really = 00 in hex = 0 in binary. If you feel comfortable editing the hex code directly you can convert the document from ASCII to hex in notepad ++ under the plugin menu, and use this to figure out the characters http://www.ascii-code.com/
But for the purpose of the guide we are going to ignore the NUL symbols and change the characters. If it helps you can make a copy and open it in normal notepad because it doesnt show the null characters, BUT YOU CAN NOT USE NOTEPAD TO EDIT IT. So to set a key so it will use an alternate key when ALT(SYM) is pressed you need to find 5th instance of that in the document, so in this case I want to make the "," and "." keys be "<" and ">" when SYM is held down, so I need to change the 5th definition for the , key to < so it should look like this
Code:
NUL,NUL,NUL,NUL;NUL<NUL;NUL


And the same for the "." key
Code:
NUL.NUL.NUL.NUL:NUL>NUL:


From what I understand from poking around on the files from my phone and looking at things on the internet the first two times the character appears is defining what key has what attributes, the 3rd one is the lowercase, 4th is the uppercase, 5th is the ALT and 6th is the ALT+Shift. So with out all the Nulls this is what the Key Character Map for A looks like, A A a A a A and for "," it is , , , ; ; ; but for our edited version it is , , , ; < ; because the 5th spot is the one that represents the character you will get when you do that key + ALT.



Now to get the file back onto your phone do what we did before but put it in /system/usr/keychars/omap-keypad.kcm.bin

Make sure your permissions are the same as the one for the omap-keypad.kl

Restart and you should have a working Alternate Key Character
Attached Files
File Type: apk KeynrTracker.apk - [Click for QR Code] (8.3 KB, 197 views)
File Type: zip omap-keypad.kcm.bin&.kl.zip - [Click for QR Code] (1.2 KB, 121 views)
The Following 5 Users Say Thank You to moah909 For This Useful Post: [ Click to Expand ]
 
valhala.awaits
Old
#2  
Junior Member
Thanks Meter 0
Posts: 2
Join Date: Sep 2011
Awesome, can't wait to try this out. I haven't looked at all of this quite yet, but i am hoping to be able to remap caps lock, the most useless key ever, to something better. Thanks for your work!

Sent from my DROID4 using XDA App
 
kasouti
Old
#3  
Junior Member
Thanks Meter 1
Posts: 5
Join Date: Apr 2011
The guide was amazing helpful for binding >< and changing caps lock to be an alt key, but I was wondering if you had any idea which file would have the operations for alt + backspace to make it clear a whole line. Again thanks for the guide.
 
tliebeck
Old
#4  
tliebeck's Avatar
Senior Member
Thanks Meter 1453
Posts: 894
Join Date: Sep 2010
Location: Southern California
Quote:
Originally Posted by valhala.awaits View Post
I haven't looked at all of this quite yet, but i am hoping to be able to remap caps lock, the most useless key ever, to something better.
WHAT THE HECK ARE YOU TALKING ABOUT? CAPS LOCK IS THE BEST KEY ON THE KEYBOARD. THIS IS BLASPHEMY.

(Sorry couldn't resist )

Keyboard maps out pretty well, I did

quote -> backquote
I -> pipe
O P -> { }
K L -> [ ]
/ -> \
, . -> < >
Q -> tilde

Used CAPS LOCK as my alt key.
Left the SYM key entirely alone.

Half tempted to make caps lock and OK shift keys, make sym key the OK key, and make shift key the ALT key.

BTW, ALT+arrows and backspace work as they did on the Droid 1/2/3.

Thanks so much for posting this, really has made the Droid 4 keyboard *SUBSTANTIALLY* better!
 
moah909
Old
#5  
Member - OP
Thanks Meter 20
Posts: 70
Join Date: Oct 2010
Location: Sekret

 
DONATE TO ME
Quote:
Originally Posted by kasouti View Post
The guide was amazing helpful for binding >< and changing caps lock to be an alt key, but I was wondering if you had any idea which file would have the operations for alt + backspace to make it clear a whole line. Again thanks for the guide.
I'm not sure, neither of my phones(OG Droid, Droid 4) have had that functionality so I'm not sure what makes that work. If you want you can send me your keylayout and keychars folders from your old phone(Droid 2/3?)that had that, through a PM and I'll try to figure out how to add that.
The Following 2 Users Say Thank You to moah909 For This Useful Post: [ Click to Expand ]
 
me_droid
Old
(Last edited by me_droid; 28th February 2012 at 11:20 PM.)
#6  
Junior Member
Thanks Meter 1
Posts: 3
Join Date: Nov 2010
Default kb remap

moah99 thank you thank you thank you. The one key I totally miss from my D1 is the @ key and thanks to you I have remapped the useless caps lock key to @. Caps lock would be useful except I use swiftkey that renders it inoperative on the D4.

After finding the correct key (222) with keynrtracker, I completed the rest using rootexplorer - backed up that file, mounted the containing folder as r/w, opened file in text editor, edited the correct line to show AT instead of CAPS, rebooted phone and it worked perfectly.
 
H0H3N5T3RN
Old
#7  
Junior Member
Thanks Meter 0
Posts: 3
Join Date: Mar 2012
Default Tried this but....

I tried changing the key 222 (Caps lock) to power the phone off and on (when i text people and I'm watching tv i typically just leave the keyboard open and lock the phone, but the power button isn't exactly easy to find) so i wouldn't need to use the power button on top. It didn't work, is there anyway i can get it to work?

Thanks,
Jacob
 
kasouti
Old
#8  
Junior Member
Thanks Meter 1
Posts: 5
Join Date: Apr 2011
Quote:
Originally Posted by moah909 View Post
I'm not sure, neither of my phones(OG Droid, Droid 4) have had that functionality so I'm not sure what makes that work. If you want you can send me your keylayout and keychars folders from your old phone(Droid 2/3?)that had that, through a PM and I'll try to figure out how to add that.
Looks like it does support it. For some reason it was just buggy at first and didn't seem to respond to alt then left. As for the delete, I was coming from an epic and my friend with a droid 2 had told me the alt then delete would wipe the line, apparently alt has to be held when it's hit and within texting you either need 2 blank spaces before pressing it or to have just finished deleting a word. Or some odd rules like that. Thanks for the help.
 
highlandsun
Old
#9  
Recognized Developer
Thanks Meter 253
Posts: 806
Join Date: Sep 2009
Location: Los Angeles

 
DONATE TO ME
Hmmm. I'm running into some oddness here, the shifted number keys look right in the kcm.bin file, but they don't work in Connectbot. It looks like they're being treated like ANSI function keys instead. Anyone else know what's up here? I've never owned a Droid-anything before, my previous two phones (G1 and TP2) keyboards work fine in Connectbot.
T-Mobile G1 / radio 2.22.28.25 / SPL 1.33.0013d / Recovery RA-dream-1.7.0 / FroyoByLazlo-4
T-Mobile TP2 (RHOD210) / radio 4.49.25.57 / WM6.5 / XDAndroid FRX06+Fixes
Verizon Droid4 / 6.16.217.XT894
 
GambitDash
Old
#10  
Junior Member
Thanks Meter 0
Posts: 3
Join Date: Dec 2010
Quote:
Originally Posted by highlandsun View Post
Hmmm. I'm running into some oddness here, the shifted number keys look right in the kcm.bin file, but they don't work in Connectbot. It looks like they're being treated like ANSI function keys instead. Anyone else know what's up here? I've never owned a Droid-anything before, my previous two phones (G1 and TP2) keyboards work fine in Connectbot.
See (http ://code.google.com/p/connectbot/issues/detail?id=558) Issue 558 on ConnectBots site.

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes