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
(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
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
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
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
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
And the same for the "." key
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