yashsingh1/xdaforums huggingface dataset:
[G2 and Desire Z Android Development] Superfrag:
Dude, there are three shortcut keys. If you could map one of them to ^, since its completely absent, it would be AWESOME!
[G2 and Desire Z Android Development] ratchetrizzo:
Yes, I third the suggestion for a ^.

It pisses me off that there is no long press to get a ^. Even the slide had that.
[G2 and Desire Z Android Development] teferi:
I should have an 0.2 up later today. I'm probably going to move "\"/"|" to the left soft key; make the two right soft keys "["/"<"/"{" and "]"/">"/"}"; and make alt-Z "^" (since we now have a dedicated Tab key).

Long-presses are way out of scope for what you can do with hacking KL/KCMs, sorry. I have no idea how that mechanism works, if it exists.
[G2 and Desire Z Android Development] ratchetrizzo:
No, I didn't imply I wanted long press anything. I was simply venting on how pissed I was that HTC didn't include a ^ in anything but a virtual keyboard on this when the slide had a long press of a actual key to get a symbol ^ up.

Anyhoo, you are awesome for doing this, it makes the keyboard even better for me!

Thank you very much kind sir for taking the time to do this for the community!
[G2 and Desire Z Android Development] spullar:
I understand it would be more complicated, but this is something I've been hoping for this from when I first got my phone. I keep my fingers crossed that teamdouche will add long touch for alt keys as that is the ONLY thing I don't like about my G2. Coming from the G1 with the dedicated number row, long touch for numbers and symbols would make my phone experience so much more enjoyable.
[G2 and Desire Z Android Development] dhkr123:
Very sorely missing key... "`" (back quote), VERY important for command substitution.

Redundant keys:

menu (exists on the soft buttons by the screen),

search/magnifying_glass (wtf, does anybody EVER use this???!?! plus, also on the soft buttons),

euro (how many people really need a euro button in everyday use in north america?)

com/www (duh... pointless.)

All told, I see (including the blanks...) a total of 6.5 buttons that can be reassigned to more useful functions (the extra .5 since the other side of the non-alt version of the euro button is the letter X, without which you cannot spell xylophone).
[G2 and Desire Z Android Development] perquisitor_omnia:
Well, I know in bash/sh you can use $(...) to accomplish the same thing.
[G2 and Desire Z Android Development] misteropinion:
And while it's one more character to type, it's also waaaay more easily nested, too.
[G2 and Desire Z Android Development] keenerb:
Dude, where were you two weeks ago when I was trying to get keycodes to fix Dosbox???
[G2 and Desire Z Android Development] teferi:
Kibitzing with the other people working on getting S-OFF for the G2. I didn't feel motivated to start on this until it was going to actually be possible :)

Good luck finding keycode labels for the G2 keyboard. There are ones that aren't in the AOSP tree, and I think the ones in the CM tree have different names from what HTC uses...anyway, talk to me on IRC (teferi on freenode) and I'll do what I can to help.
[G2 and Desire Z Android Development] JanetPanic:
You sir are a gentleman and a scholar. | on particular pained me greatly with its absence. <> are useful and I could definitely use ^ but the lack of pipe was the worst of it for me.

Thank you from the bottom of my heart.
[G2 and Desire Z Android Development] Barret7sc:
Any chance I could get a quick explanation on what the binary files actually do? Looks like you should be able to remap the keyboard just by changing the .kl file.

I'd like to write a tool to automate this and be able to change the keyboard layout, I just need some more information on how things interact. I'm going to do some research myself but it seems the android docs are a bit lacking in this area.

Thanks!
[G2 and Desire Z Android Development] perquisitor_omnia:
That's an understatement.

I don't suppose that there is a way to decompile the kcm files? Or do I need to start working backwards from the tool that compiles them?

I really don't want to have to use a hex editor.w
[G2 and Desire Z Android Development] Barret7sc:
I was able to grab the kcm utility from the Android git repository and get it to build. The problem is we don't have a plaintext version of the .kcm file to edit.

I shall press on however!

This is helping. Looks like I may have to write a reversing tool for the binary files.

http://source.android.com/porting/keymaps_keyboard_input.html
[G2 and Desire Z Android Development] perquisitor_omnia:
Cool, I wanted to script a way to change these automatically, the fact this is written in python all the better.

(if I can make it so that ALT-SHIFT-Number Key sends the codes that ConnectBot recognizes as function keys that would be perfect)
[G2 and Desire Z Android Development] nyflyguy:
Will this work with cyanogen?
[G2 and Desire Z Android Development] perquisitor_omnia:
Can't see why you couldn't mod cyanogen's keymap files. Its part of the Android framework not a G2 thing.
[G2 and Desire Z Android Development] reukiodo:
Anyone else having problems with the '?' key with this? I'm using CM 6.1

Edit: nevermind - I can't use '?' on default CM either...

Edit2: could you include the '?'/'"' key in this keypad.kcm.bin file?
[G2 and Desire Z Android Development] Barret7sc:
So I'm pretty sure that the 97, 98, and 99 values are USER1, USER2, and USER3, and 105 is QUECHAR as referenced in the .kl files.

The KCM utility will have to have it's KeycodeLabels.h file modified to include these values in order to compile the KCM file to a kcm.bin file.

I'm going to do some fooling around and see what I can tweak. I'm still looking for a way to write a utility to automate this on the phone itself.
[G2 and Desire Z Android Development] Barret7sc:
Ok, so here is the compilation of my research into how this and the tools you need to make this work with your own custom keyboard layouts.

View attachment kcm_utils.zip

This file contains the windows kcm.exe executable that can compile kcm files into kcm.bin files, the modified source files that are needed to compile kcm.bin files for the G2, the modified unkcm python script that allows you to decompile an existing .kcm.bin file.

It also includes the original .kcm and .kl files from the G2.

Now, if you simply want to remap keys you only need to modify the .kl file and upload it to your device. For example, if you want to change Quick Key 1 into a backslash/pipe key you only need to change one line.

From this:

key 183 USER1 WAKE_DROPPED

To this:

key 183 BACKSLASH WAKE_DROPPED

The tags USER1 and BACKSLASH refer to entries in the .kcm file. You can use any of the constants defined in the .kcm file for any key on the keyboard. They labels are quite easy to understand.

Now, if you want to actually change what keys are sent upon a keypress, you need to change the .kcm file. For example, there are no angle brackets defined on the G2 keyboard. I changed the RIGHT_BRACKET and LEFT_BRACKET keys to send angle brackets when ALT is pressed on those keys. This involves changing the .kcm file

From this:

# keycode Display Number Base Shift Alt Shift+Alt
LEFT_BRACKET '[' '[' '[' '{' '[' '{'
RIGHT_BRACKET ']' ']' ']' '}' ']' '}'

To this:

# keycode Display Number Base Shift Alt Shift+Alt
LEFT_BRACKET '[' '[' '[' '{' '<' '{'
RIGHT_BRACKET ']' ']' ']' '}' '>' '}'

Then you compile the modified kcm file using the kcm.exe utility

kcm vision-keypad.kcm vision-keypad.kcm.bin

Then upload it to your device and copy it to the /system/usr/keycodes folder as indicated in the OP.

Also, you will want to disable the quick keys app so that it doesn't pop up each time you press one of the quick keys. This can be done with the following shell command (Requires root, of course)

pm disable com.tmobile.userkeystool

I know this may be a bit sparse on details, but I hope it helps folks who want a custom keymap for their device.
[G2 and Desire Z Android Development] IConrad01:
Any chance of getting a Linux-compatible version of this? It won't work w/ WINE.
[G2 and Desire Z Android Development] Barret7sc:
The source for the executable is included. It should compile with gcc just fine as it was compiled with GCC under Cygwin.

Change to the src directory and compile it.

The command should be something like this:

g++ -I ./ kcm.cpp

Now, if this behaves the same way on linux as it does under cygwin you should get a file named "a.out", you can rename this file to something like kcm and then run it.

For example:

mv a.out kcm
./kcm

I tested this using Ubuntu 10.10
[G2 and Desire Z Android Development] ratchetrizzo:
Any chance the OP is going to add a ^ key to the map?

Aside from that, It's pretty hunky-dory as is.
[G2 and Desire Z Android Development] the orange bandit:
This is pretty awesome - I just loaded a Desire Z ROM on my G2 and you lose the www/.com key, as well as the first quick key. Any chance someone could upload a stock one with the www/.com key restored and maybe the first quick key as a 'back' button (since there's not a hard 'back' button).
[G2 and Desire Z Android Development] Weaseal:
Hi Teferi,

Thank you for giving me my | key back!! I want to have your babies.
[G2 and Desire Z Android Development] Stryder5:
Has anyone tested this on a Sense ROM?
[G2 and Desire Z Android Development] KronicAnarchy:
+1,

I was going to just use the orig file in the OP and see if it works, worst case I have to restore right??
[G2 and Desire Z Android Development] the orange bandit:
Definitely report back and let us know how it works.
[G2 and Desire Z Android Development] KronicAnarchy:
Will do but it probably won't be until the weekend when I've got time to mess with it.
[G2 and Desire Z Android Development] wilnotdie:
More and more good stuff popping up here.

Does anyone know how to set the quickkey to toggle wifi on/off?

I know I probably dont need to remap the key but I cant figure out the code that is used. I know its there somewhere, the WiFi widget does it with one simple click, we should be able to too. Im just not a programmer, and have no idea how to read and implement logcat data :(.
[G2 and Desire Z Android Development] the orange bandit:
I have LauncherPro installed (I haven't set it as my default homescreen yet, but probably will - it's what I normally use). LauncherPro lets you set shortcuts to 'actions', which include various things. I used this to set one of the quick-keys as 'home' so I don't have to reach up to the touch-sensitive key. There's no reason you couldn't also use this to toggle wifi.
[G2 and Desire Z Android Development] wilnotdie:
I'll have to check it out. Ive tried AnyCut but the only actions it allowed was to open the Wireless Settings. I made a simple script which i linked to the quick key through gscript. but its only temp.

Thanks tho, i'll give LauncherPro a shot.
[G2 and Desire Z Android Development] ollehal:
olle@seven keys $ python unkcm vision-keypad-nor.kcm.bin vision-keypad-nor.kcm

Traceback (most recent call last):

File "unkcm", line 178, in <module>

decompileKCM(f, output)

File "unkcm", line 161, in decompileKCM

Out.write(kr.printKR()+"\n")

File "unkcm", line 142, in printKR

fmt = (rkeycodes[self.keycode],)

KeyError: 101

Seem nordic one has some more chars like åäö and stuff that python script do not like at all. I can decompile the other ones.

I'll include vision-keypad-nor.kcm.bin if anyone is up for a test.
[G2 and Desire Z Android Development] Barret7sc:
Could you post your .kl file as well. Going to need this to know how to modify the python decompiler and the C++ kcm compiler.
[G2 and Desire Z Android Development] Barret7sc:
Nevermind, I found the right one in a sense rom I downloaded.

I have updated the KCM utils so it *should* handle all the .kcm.bin files so you can change them for any keyboard layout.

This includes the same as the other attachment, but with fixes to support the international keyboard layouts.

I have named the keys I can't identify as UNKNOWN100 - UNKNOWN104. The names don't really matter though.

Anyway, here is the file!

View attachment kcm_utils_v2.zip
[G2 and Desire Z Android Development] ollehal:
olle@seven keys $ ./kcm vision-keypad-nor.kcm vision-keypad-nor.kcm.bin

vision-keypad-nor.kcm:59: expected keycode label or number near: UNKNOWN101

vision-keypad-nor.kcm:60: expected keycode label or number near: UNKNOWN102

vision-keypad-nor.kcm:61: expected keycode label or number near: UNKNOWN103

vision-keypad-nor.kcm:62: expected keycode label or number near: UNKNOWN104

And it doesn't work.

I'll add the output files along with the original working one and stuff.. You can see they are diffrent.. and as stated, doesn't work... :(

Sidenote: If you look in the original file you'll see our swdish chars are in iso-8859-1 and not utf-8
[G2 and Desire Z Android Development] Barret7sc:
Weird. It works fine with the supplied exe file in Cygwin.

You might try re-building the binary from source see if that fixes it.
[G2 and Desire Z Android Development] ollehal:
Using wine it worked, could be 64bit compiler/version/bla bla bla.. funny :)
[G2 and Desire Z Android Development] Barret7sc:
Wouldn't surprise me if it's a 64 bit compatibility issue.
[G2 and Desire Z Android Development] tijuanacartel:
Awesome work! I just tried this on my Z and the original files have exactly the same md5sums. However the replacements dont seem to have any effect, at least in the apps I've tried. I will definately be using your tools to remap the keys for the Z more efficiently.
[G2 and Desire Z Android Development] jamaicada:
Is it possible to do two different layouts with different languages?

If yes, how can I do this?

P.S I know how to change layout files, I just wonder if I can add second language to the hw keyboard.
[G2 and Desire Z Android Development] teferi:
It should certainly work on the Z with CyanogenMod. Dunno about stock. I can only test this with what I have, and what I have is a G2 running first stock and then CM.

I have no idea how language switching for keymaps works. Sorry.
[G2 and Desire Z Android Development] petard:
For the Desire Z the keymap files are vision-keypad-wwe

They are different to accomodate for the slightly different things on the Desire's keyboard.

How does the OS know which one to load?
[G2 and Desire Z Android Development] roadrunnerx7:
is there any chance this could be turned into a fully functional app? and then work on a non rooted g2?
[G2 and Desire Z Android Development] teferi:
The OS picks a keymap for keyboard #N based on the hw.keyboards.<N>.devname system property.

Could it be turned into an app, with a nice GUI? There's no reason why not, though I'm not personally really inclined to do it - as I said before, my itch is scratched with this keymap. For a non-rooted G2? Absolutely not. The search paths for keycharmaps and keylayouts are hardcoded in Android, and they're on /system.
[G2 and Desire Z Android Development] tijuanacartel:
Any chance of this working on the Z? It doesnt work with Sense ROM.
[G2 and Desire Z Android Development] teferi:
It doesn't work on the DZ because the Z's keyboard's device name is vision-keypad-wwe. I haven't gotten around to hacking it up yet, but I imagine it's not too different.
[G2 and Desire Z Android Development] xzxxzx:
Thanks for this; exactly what I was looking for.
[G2 and Desire Z Android Development] elusivebyte:
Summary: I messed up the permissions on the files which made the keys on the screen (Home, menu, etc.) not work at all.

Woah, this broke my phone in multiple ways. I'm on CM6.1 RC2 with a G2.

I'm pretty sure I didn't do anything wrong during the install, but I didn't do it via ADB, so who knows. I used ADB to push the files to my SD card. Then I used Root Explorer to copy them to the specified folders after using the Mount R-W button. Then I rebooted via the power button.

After reboot, none of my softkeys work. (Home, Menu, Back, or Search). They cause vibration when pressed, but don't perform their function. The Quick Keys don't do anything either, still. Alt-Z is now caret (^) as expected. .com appears to be Tab. It no longer types www. or .com, at least. It's hard to navigate on my phone to try the .com key in various apps because once I launch one, I can never get back to my home screen! I have to reboot to launch a new app. :D

I'm going to try to replace the files with the original copies now. I'm kicking myself for not doing a nandroid backup first. I do have an old backup I can restore to if I have to.

Any clue what I might have done wrong? When I pasted both files it asked if I was sure I wanted to overwrite, so I know I copied the two files to the right place. It's really not that hard to copy files. I don't see how I screwed anything up. I'm a software engineer, so I'm not exactly a noob.

UPDATE: I followed the exact same steps with the .orig files after I renamed them to remove the .orig. My soft keys still don't work. I'm going to do a Titanium Backup of all my apps, then restore my most recent Nandroid backup. Gah, I don't even know if my latest backup is RC2 or RC1. Doesn't really matter. If it's RC1, I'll just update again like I did before. After I restore the backup, and hoping things are working again, I'm going to compare my original files to the original files provided in the zip to see if there are any differences. I don't see why my phone would be special, though. Don't these files come as part of CM6.1?

UPDATE 2: Thank god the restore made my keys work again. I was scared that something serious got messed up and they still wouldn't work. I will extract the files and do a comparison now.

The .orig files and the ones I just pulled off of my restored system are identical. I did a binary comparison. So I don't know what happened. Maybe the permissions on the files were set wrong when I used Root Explorer to copy them? I did a Nandroid backup of the messed up system, so I can go check after I update back to RC2 and take a fresh backup of my good system.

UPDATE 3: That was indeed the problem. The permissions on those two files were messed up. They were set to ---rwxr-x instead of rw-r--r--. I fixed the permissions, rebooted, and all is well. Now I'm going to try the modded keymap the right way this time. :D

Yay! Modded keys. Thanks!
[G2 and Desire Z Android Development] dadewy:
Working just fine here on virtuous .72 (vision.keyboard.* files, not -wwe as on a real DZ/sense, just FYI).

I put user3 button as DPAD_CENTER and now it functions as a CTRL key in better term. That combined with a proper TAB key just makes things SO much nicer.

As an aside, "special" keys remapped like this become mappable in apps like gameboid and such, which is cool.

Thanks guys!
[G2 and Desire Z Android Development] khaosxiii:
Thank you God!1111 (and OP)
[G2 and Desire Z Android Development] decksy:
hey elusivebyte, thanks for posting your problem and solution! i ran into the same problem and your post saved me the headache!
[G2 and Desire Z Android Development] jummama:
[PATCH] making the www./.com button more useful

Just a simple keylayout patch to turn your www./.com button into a backslash (\) key, along with a pipe (|) if shifted. Simply grab this and put it in place of /system/usr/keylayout/vision-keypad.kl, then reboot, or manually edit your existing file and replace the key 150 item with BACKSLASH or whatever else you might want instead of whatever it was before. Not a real complex patch, but I'm sure I'm not the only one that wanted to pipe things around and escape strings in the terminal without quotes or the onscreen keyboard!

Also, in vision-keypad.kl, at the bottom is a list of unused, but mappable key mappings, if you want something other than backslash.
[G2 and Desire Z Android Development] itp:
Have you seen http://xdaforums.com/showthread.php?t=837002 ?

It's a somewhat more comprehensive keyboard remap, although you do give up the (almost completely useless) quickkeys in the bargain.
[G2 and Desire Z Android Development] jummama:
Awesome! Thanks for the heads up... I was thinking of doing something along those lines later on, but I see the work has already been done...
[G2 and Desire Z Android Development] grdnwsl:
Ok, so I'm having trouble getting the remapped .com button to work in connectbot. According to adb logcat connectbot gives the following error when I hit "tab": ESC unknown letter: g (103)

Any ideas?
[G2 and Desire Z Android Development] charlieton:
Can anyone help? I get this error. I'm win7x64 bit if it matters. I know that when pushing the files I couldnt do:

adb push vision-keypad.kl /sdcard
failed to copy 'vision-keypad.kl' to '/sdcard': Is a directory

And had to use:

adb push vision-keypad.kl /sdcard/vision-keypad.kl
12 KB/s (3322 bytes in 0.261s)

This is what I'm getting now:

# cp -f /sdcard/vision-keypad.kl /system/usr/keylayout/
cp -f /sdcard/vision-keypad.kl /system/usr/keylayout/
cp: can't create '/system/usr/keylayout/vision-keypad.kl': File exists

Thanks!
[G2 and Desire Z Android Development] ratchetrizzo:
prior to copying the stuff to /system/usr do a (and make sure your sdcard is NOT mounted as a drive in windows)

adb remount

and as far as your first problem with the adb push to /sdcard, if you did adb push filename /sdcard/ it would have worked fine, sometimes you have to have the ending /
[G2 and Desire Z Android Development] charlieton:
Thank-you! that worked :)
[G2 and Desire Z Android Development] dixxa:
Will this mod activate some French letters like è or é. Since I have Cyanogen, I can't type them on my keyboard :s
[G2 and Desire Z Android Development] reukiodo:
Have you tried holding down the 'e' key for a moment? On most androids, it will pop up a menu with the è, é, and such variants.

Same also applies for a, c, i, o, u, and probably others.
[G2 and Desire Z Android Development] southpaw773:
What I'm trying to do is program a quick key on my g2 to be the escape key ("back"). it would be more convenient/less thumb travel thant he escape <--| key that is currently on the front of the phone. is there an easier command to type in to anycut or something instead of remapping with hacks? kthx
[G2 and Desire Z Android Development] zitback:
hi all!

Guys, you are genius, i dont even understand how to do things :S :D

I would like to make the shourtcut keys, to work as CURSOR_LEFT and CURSOR_RIGHT ....with shift+ : CURSOR_UP and CURSOR_DOWN

Is there a way to do this?

OR maybe: is there somebody who can make this .kl and .kcm for me? :S Im a noob user, dont know how to do these things :S I would be thankful!
[G2 and Desire Z Android Development] smoochiezz24:
I used buttonremapper http://xdaforums.com/showthread.php?t=850464 and changed one of the "User" keys to "back". I changed "User2" because it just feels right to me to have the back key close to the period.

Now, onto my project... im trying to make Alt+z=dpad up and Alt+x=dpad down. Basically, I'm trying to replicate my trackpad on my keyboard for when im browsing the web or any other app. I have the two files (the .kl and the .kcm.bin) Im viewing the .bin file in a hex editor. However, I dont want to replace my keys with another character, but instead with an "action". The "action" being up,down,left,or right. Is this possible at all?

If that can be done, then can the menu key be used as a modifier? I noticed that some apps such as dolphin browser hd use menu+f to search the page for words. So it is somewhat possible. I just wouldnt know where to configure it. But if it can be done, my perfect layout would be Menu+I= up ,Menu+K=down ,Menu+J=left ,and Menu+L=right
[G2 and Desire Z Android Development] zitback:
I'm intrested in your idea! It's very good! I really need a D-Pad, and MENU+I,K,J,L

would be perfect! Unfortunately, i don't know how to make it...my phone is not even rooted, but it would be very great if someone could make this modification!