[DEV][HOWTO] How to decompile kcm.bin to remap keys properly. - G2 and Desire Z Android Development

Someone please explain how to properly decompile the kcm.bin so that it can be edited and recompiled. There are quite a few of us who would like to remap certain hardware buttons (mainly custom user keys) but just using the files from (this thread) leaves us with some broken keys, the "?" key mainly... but some would also like to tweak this layout and don't have a proper tutorial. I will gladly donate a minimum of $10USD to the first person who properly explains the process for both *nix and windows environments.

This is another approach.
(If you have already read this and it is not the way you want it, I am sorry)
According to http://forum.xda-developers.com/showthread.php?t=1285244&page=3
In short:
# Remount
adb shell
su
mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system
# fetch Keylayout
adb pull /system/usr/keychars/vision-keypad-wwe.kcm.bin /tmp/vision-keypad-wwe.kcm.bin
# edit Keylayout according to Thread above with a hex editor
For example A 2 a A ! ! that represents:
A: Scancode
2: Does not matter
a: Letter when button connected to the keycode is pushed
A: SHIFT + button connected to the keycode is pushed
!: ALT + button connected to the keycode is pushed
!: SHIFT + ALT + button connected to the keycode is pushed
(for me ALT = FN)
# push it back
adb push /tmp/vision-keypad-wwe.kcm.bin /system/usr/keychars/vision-keypad-wwe.kcm.bin
The first line in every row is the constant value of the keycode.
For example: http://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_A
For Button A it is: 29 in decimal, 1D in hex.
With this approach you can change every key, but only the printable characters.
Search button will not work, as it is implemented in another way...

ok, not sure if I missed something, but specifically I need to modify the ? key and the 3 user assignable keys on the g2/dz keyboard... I don't see in the hex editor any line that starts with the ? symbol then has a number and two more chars/symbols after the number (ie: A 2 a A ! ! )
when I load keynumber tracker app the ? key reports "214" the user assignable keys report 183, 184 and 185... I'm just not sure what to do with those numbers, or how they help me modify anything...
I guess I just don't understand what I'm doing...
Ok, so I noticed in hex editor that the only difference between the modded kcm.bin and the stock one where my ? key works (besides the remapped keys) was the last 64 blocks of hex so I copy /pasted that part to the modded kcm.bin then saved and pushed... Now it's working, thanks so much, will PM you momentarily to get your paypal addy. Sooooo happy!!!
Edited w/ a cold press a CNC and a water jet @ 30,000PSI.

Related

Tilt2 CTRL key

I am using an AT&T Tilt2 with stock ROM. I am not being able to get a key on the hardware keyboard to remap to CTRL.
I have tried manually editing the eT9.Rhodium.Cingular_US.kmap.txt file (using 0x11 for the value). I have also tried using the Rhodium Keyboard Controller. Neither seem to do the trick. The key I remap (tried OK, home, and several others) stops doing the original function. Instead of what I would expect for CTRL it just does nothing.
For now I have mapped fn-C -> CTRL-C and such, but I would like to get a key to actually map to CTRL.
Any ideas on how to get this to work?
I agree.
Bump for more interest please.
Anyway to add CTRL to the stock SIP touch keyboards too?
I miss my Ctrl-A (select all) / Ctrl-C (copy) / Ctrl-V (paste) amongst other common keyboard commands too!
~J
im afraid you will have to flash custom rom to enable ctrl remapping
For the kmap bit did you use the 0x11 as the second value? IE did you change it to something like:
{0xEC 0x11 0x00 0x00 0x00 0x00} //example for the FN key remap.
Also make sure to use something like Notepad to modify the file. It needs to be saved as unicode.

Bluetooth Keyboard and custom key and character mapping

Some custom ROMs, which are not based on HTC roms, but compiled form Android Source support the Bluetooth HID profile, thus support well known and common normal Bluetooth keyboards.
I've tested Cyanogenmod and OpenDesire.
However, I was unsatisfied with the keyboard layout. I've found no key for return, needed some special 'Umlaute' for my German layout, etc.
Here's what I've found to fix all this:
1. Description what can be changed:
Android Open Source Project: Keymaps and Keyboard Input
Until now I don't know the internal differences between the key map and character map files. Sure, both look different, both can and must be changed for different reasons. The key map if you want to change actions and also alter phone buttons, the character map for modifying the full layout. But with the key map you could also alter parts of the layout, so it's not that clear for me. However.
2. Altering Key Map Layout
If you don't specify a keylayout file, Android will default to /system/usr/keylayout/qwerty.kl
Click to expand...
Click to collapse
So I took a look at this file, changed it, and it worked
Here a nice explanation of this file, explained are the different commands, too.
[GUIDE] How to Remap Hardkey Actions || Custom App Launching
What we not know, the key number of our physical BT keyboard, so what's the number of ESC? For this, I've found following site, which seems to contain the correct scan codes, used in Android: (note, the values are in HEX!!)
http://www.marjorie.de/ps2/scancode-set1.htm
So if we take a look at ESC:
Key: ESC Make: 01 --> in decimal, stays 01
We just have to add following line to the key map layout file:
key 1 BACK WAKE_DROPPED
and we have a back key.
3. Altering Character Map file
To change characters and change the whole layout, it seems as if we have to alter the character Map file. (/system/usr/keychar/qwerty.kcm.bin)
Sadly, this fact makes editing the file somehow difficult:
Resource Binary File Format
The file snippet above [see first link] gets converted to the following [a binary file] by the makekcharmap tool as part of the build process.
Click to expand...
Click to collapse
I have no idea what this tool is, nor how to revert it back, so we have to edit the binary file. Luckily, one user's done the hard work already, again:
Changing to a non-english keyboard layout [cupcake support]
The easiest method is to use some kind of hexeditor, so you see what you do and can enter the character code of special characters easily, I used the one in Notepad++
Then you can alter the layout just as you like. Because I have a special english keyboard with which I want to type german Umlaute, too, I changed
A.2.a.A.#..
to
A.2.a.A.ä.Ä.
So I can type an 'ä' by holding the 'Alt' key and pressing a. Typing 'Ä' by holding Shift+Alt and typing 'a'.
Unlimited possibilities
Tips:
To alter both files you can use ADB and an editor on your computer.
Or you can alter the files directly on the phone, without any additional hardware. You only need Root Explorer to open, change and save the files directly on the phone.
Drawbacks of changing the layout:
Haven't seen some yet

Enable on-screen buttons

As I don't like the default button layout, I enabled the on-screen buttons and disabled the hardware buttons.
In case someone wants to do that, too, I thought I just post the instructions here:
1) Enable on-screen buttons
Edit the file /system/build.prop and add the following line:
qemu.hw.mainkeys=0
2) Disable hardware buttons
Edit the file /system/usr/keylayout/ft5x06.kl and comment out the following lines:
#key 139 MENU VIRTUAL
#key 102 HOME VIRTUAL
#key 158 BACK VIRTUAL
#key 217 SEARCH VIRTUAL
3) Reboot
Tested with CM11. Not sure if this would work on MIUI.
Thanks @chris5s and several other forum users. I know that there are a couple of similar posts for other phones. But I still hope this is helpful so that Redmi 1S users don't have to look in another place.

Change 3rd party remote key layout (root require)

Use as your own risk! a wrong keylayout may totally disable the input device. Tested on Shield TV 2017 16GB
If you are using 3rd party remote on Shield TV some key may not work as intent, or you want to remap the key for another function, for example I had a xiaomi remote (just $4 dollar) which the home key not working.
Although you use custom IME (such as mkr Multilanguage Keymap Redefiner) or some keyboard remap app (such as buttons remapper), which work but not perfect, some function may not work such as double press the home button to show recent app list, or conflict with shield tv controller button (buttons remapper disable the voice search button on my shield controller), and you may need to change every time for each different remote/controller.
Luckly android allow you to use specific key layout for each different remote.
1. flash the developer image, which is pre-rooted, or root it yourself
2. adb shell
3. cat /proc/bus/input/devices
Now you will have a list of connected remote/controller, take a note of the Vendor number and the Product number​4. adb pull /system/usr/keylayout
5a. modify a exist keylayout file, or create a new one. The file name should be Vendor_XXXX_Product_XXXX.kl, Don't change the Generic.kl
5b. use any keytest app to check the key scancode, I am using "Multilanguage Keymap Redefiner"
for example my xiaomi remote home key scancode is "102", which map to MOVE_HOME by default, so I create a new file "Vendor_2717_Product_3200.kl", the file will be like this:​key 28 DPAD_CENTER
key 102 HOME
key 103 DPAD_UP
key 105 DPAD_LEFT
key 106 DPAD_RIGHT
key 108 DPAD_DOWN
key 114 VOLUME_DOWN
key 115 VOLUME_UP
key 116 POWER
key 127 MENU
key 158 BACK​
Any key not listed will be disable, so make sure you have all key listed
6. copy the file back to shield tv:
adb root
adb disable-verity
adb reboot
adb root
adb remount
adb push "layout file" /system/usr/keylayout​7. reboot.
P.S. Don't change the Generic.kl, change the keylayout file one at each time
Shield TV remote Home button is map to HOME, and the dpad center is map to DPAD_CENTER, so other remote which map to MOVE_HOME and ENTER (such as my xiaomi remote) will need this mod
The shield TV come with lot of keylayout file for many different controller/remote, I see MI, wii,xbox 360, but there seems no amazon
I had attach the keylayout file pull from my sheild tv, may be you can take a look which controller/remote is support offically​
I cant do adb remount, it says I have to be root, and when I do adb root first it seems to pass but it still says I have to be root when i try adb remount.
How do I set my /system to r/w instead of r/o? I have tried adb mount o rw,remount /system but it wont do anything.. also the command you tell me to use, "adb disable-verity" says:
disable-verity only works for userdebug builds
Can you please help me?
Kylistar said:
I cant do adb remount, it says I have to be root, and when I do adb root first it seems to pass but it still says I have to be root when i try adb remount.
How do I set my /system to r/w instead of r/o? I have tried adb mount o rw,remount /system but it wont do anything.. also the command you tell me to use, "adb disable-verity" says:
disable-verity only works for userdebug builds
Can you please help me?
Click to expand...
Click to collapse
you need to root it yourself or using the developer firmware in here:
https://developer.nvidia.com/gameworksdownload#?search=SHIELD
note that future OTA may fail because it will send you normal firmware even you are on developer firmware
DummyPLUG said:
you need to root it yourself or using the developer firmware in here:
note that future OTA may fail because it will send you normal firmware even you are on developer firmware
Click to expand...
Click to collapse
I did root my nvidia shield. It is supposed to be rooted, I got super user(superSU) installed on it and Everything..
Kylistar said:
I did root my nvidia shield. It is supposed to be rooted, I got super user(superSU) installed on it and Everything..
Click to expand...
Click to collapse
you mean mount -o remount,rw /system didn't work? but I suppose it can't as verity will prevent it, I hear SU in 7.0 will disable verity but I didn't try it before, sorry about this.
DummyPLUG said:
you mean mount -o remount,rw /system didn't work? but I suppose it can't as verity will prevent it, I hear SU in 7.0 will disable verity but I didn't try it before, sorry about this.
Click to expand...
Click to collapse
I actually got the kl file into the system/usr/keylayout directory now, using TWRP
with these steps:
Reboot to Bootloader
Type “adb reboot bootloader” and hit enter. The Shield TV should reboot into the bootloader screen.
Fastboot with TWRP
Type “fastboot devices” and make sure your Shield TV is visible.
If your Shield TV is listed, type “fastboot boot twrprecovery.img”
in the TWRP i can chose mount and check system, then i was able to move the .kl file from the sdcard to the keylayout directory, still my nvidia shield doesnt give it the new settings.. its given the same configuration as my nvidia controllers. I have double checked that Vendor nr and Product nr is the same as the controllers.
here's my .kl file:
# ps4
key 304 BUTTON_X
key 305 BUTTON_A
key 306 BUTTON_B
key 307 BUTTON_Y
key 308 BUTTON_L1
key 309 BUTTON_R1
key 310 BUTTON_L2
key 311 BUTTON_R2
key 312 BACK
key 313 HOME
key 314 BUTTON_THUMBL
key 315 BUTTON_THUMBR
key 316 BUTTON_START
looks correct?
Thanks for your time!
Kylistar said:
I actually got the kl file into the system/usr/keylayout directory now, using TWRP
with these steps:
Reboot to Bootloader
Type “adb reboot bootloader” and hit enter. The Shield TV should reboot into the bootloader screen.
Fastboot with TWRP
Type “fastboot devices” and make sure your Shield TV is visible.
If your Shield TV is listed, type “fastboot boot twrprecovery.img”
in the TWRP i can chose mount and check system, then i was able to move the .kl file from the sdcard to the keylayout directory, still my nvidia shield doesnt give it the new settings.. its given the same configuration as my nvidia controllers. I have double checked that Vendor nr and Product nr is the same as the controllers.
here's my .kl file:
# ps4
key 304 BUTTON_X
key 305 BUTTON_A
key 306 BUTTON_B
key 307 BUTTON_Y
key 308 BUTTON_L1
key 309 BUTTON_R1
key 310 BUTTON_L2
key 311 BUTTON_R2
key 312 BACK
key 313 HOME
key 314 BUTTON_THUMBL
key 315 BUTTON_THUMBR
key 316 BUTTON_START
looks correct?
Thanks for your time!
Click to expand...
Click to collapse
Yes TWRP can write into system, but last time when I try it trigger the verity protection sometime, don't investigate it though as I am lazy and just use the developer build since then. (another reason I semi brick my shield a few time with twrp)
the.kl looks correct, to see what is the problem try remove one of those key from the .kl, if shield load the file correctly that key should be disable, if not then the .kl file is not work.
I can't remember if the file need to be in unix EOL style or not, that means if you edit it in windows notepad it may not work, try notepad++ or pspad. (I may mix up with bt_config.conf, which I use to maually pair my xiaomi remote)
DummyPLUG said:
Yes TWRP can write into system, but last time when I try it trigger the verity protection sometime, don't investigate it though as I am lazy and just use the developer build since then. (another reason I semi brick my shield a few time with twrp)
the.kl looks correct, to see what is the problem try remove one of those key from the .kl, if shield load the file correctly that key should be disable, if not then the .kl file is not work.
I can't remember if the file need to be in unix EOL style or not, that means if you edit it in windows notepad it may not work, try notepad++ or pspad. (I may mix up with bt_config.conf, which I use to maually pair my xiaomi remote)
Click to expand...
Click to collapse
It looks like my shield wont recognize the files im putting in there, I tried replacing the Generic file with a modified one, after that the ps4 controller wont work at all, Before it just had the wrong buttons, then i tried changing back to the original file and the shield wont read it.
This should mean the reason my new .kl file for the ps4 controller wasnt recognized because of this.
Any idea what I do now? How do I get it to recognize the files? How do I get at least the generic back if that is not possible?
And yes, I do use pspad.
Kylistar said:
It looks like my shield wont recognize the files im putting in there, I tried replacing the Generic file with a modified one, after that the ps4 controller wont work at all, Before it just had the wrong buttons, then i tried changing back to the original file and the shield wont read it.
This should mean the reason my new .kl file for the ps4 controller wasnt recognized because of this.
Any idea what I do now? How do I get it to recognize the files? How do I get at least the generic back if that is not possible?
And yes, I do use pspad.
Click to expand...
Click to collapse
If you replace the generic file and it didn't work this mean the file is something wrong, the first thing I come in my mind is the file still using windows (CRLF) not Unix (LF), but as you said even you copy the original .kl back to shield it still didn't work then may be the dm-verity kick in
if it is dm-verity kick in the best and easiest way to recovey is flash the firmware again, as it is hard to modify the current system block to have the same hash as original one
I am having the same issue as above. My Shield doesn't recognize the changes made to the .kl file I edited.
I have a rooted Shield running on the latest Shield software 7.0.2 and a Fire TV Stick Remote connected.
I used cat /proc/bus/input/devices to see the remote uses vendor 1949 product 0404 key layout.
I went to system/usr/keylayouts, navigated to that kl file and then modified the 2 keys I wanted to change. Rewind and fast forward. I changed them to VOL_DOWN and VOL_UP.
I saved the changes and rebooted.
However they still act as MEDIA_REWIND and MEDIA_FAST_FORWARD.
I have verified the changes are still showing in the key layout file. I don't understand why it's not working.
The last time I rooted my Shield, I was using another Fire TV remote (the Alexa Voice Remote), which uses 1949 0407.kl file.
I modified that one to make the same changes and it worked. I could control the volume.
Since then though, I've factory reset the Shield am rooted onced again and this time I am using this fire tv stick remote, but can't seem to get the changes to the key layout file to actually take affect and I don't understand why it's not working. What is different than when I modified the other remote? Makes no sense.
EDIT: Ok so I figured it out basically right after making this post. I was trying to use VOL_UP and VOL_DOWN, which I could have sworn was the correct key code and what I used with my other Fire TV remote before I factory reset. However I tried again, this time though using VOLUME_UP and VOLUME_DOWN and it worked properly.
Damn, I'm dumb. Now it's working exactly how I wanted it to.
I am guessing by using the wrong key code, thus rendering it useless, it was falling back to the key code used for the same key ID in the generic.kl file?
thanks, i will try
How do we know the vendor number for external remote? I tried on android box and there is no system under /proc
how do i set the proper chmod when running the push command to put the file onto the device?
Thanks for this, but I am trying to use Mi remote with voice control
Everything works except the Google assistant button, it brings up assistant but doesn't detect any voice from remote.
Can something similar be done with an IR remote?
I'd love to have more buttons that I could use for all kinds of automations.
Thanks!
How to open app using this method? Suppose I want to open google chrome, how would I do that? @DummyPLUG

How To Guide How to remap "assistant" button! [ROOT REQUIRED]

it seems that while adding non-remappable assistant buttons is a growing trend, solutions aren't easy to find, however the solution is real simple, you just have to modify the keymap file...
I successfully managed to get the button detected by flashing XperiaGAButtonRemap through magisk, and I'm pretty sure the same solution works for a bunch of other phones also, it even has code that should allow flashing through custom recoveries also.
all you have to do is "install from storage" in magisk manager, select the zip, and reboot.​
what that zip does, is it adds /system/vendor/usr/keylayout/gpio-keys.kl (overriding /system/usr/keylayout/gpio-keys.kl because /vendor has higher priority) and replaces the ASSISTANT key with PROG_BLUE, which is a dummy key, you can remap that with any remapper app or module, or you could edit the zip, and change it directly to something like CAMERA, if that's all you want.
here's what the file will look afterwards, if you're curious:
key 115 VOLUME_UP
key 114 VOLUME_DOWN
key 102 HOME
key 528 FOCUS
key 766 CAMERA
key 457 PROG_BLUE
the original file has copyright notice for The Linux Foundation, from 2013, but all other keys map the same, so it's highly likely most phones (at least the AOSP-adjacent ones) just have hooks for the ASSISTANT key, but still rely on the universal keymap file
thanks a lot!worked just fine,
big ups!!!
Hello, sorry for the question, does this work on Android 12?
SHANOA_zasha said:
Hello, sorry for the question, does this work on Android 12?
Click to expand...
Click to collapse
I've just tested and yes it works in A12

Categories

Resources