• Introducing XDA Computing: Discussion zones for Hardware, Software, and more!    Check it out!

[MOD][UPDATED] Modified keymap files for G2

Search This thread

teferi

Member
Oct 1, 2010
28
6
After some quality time with the AOSP source and a hex editor today, I've come up with modified keymap files for the G2 that make the keyboard a bit more useful. It's gone through three iterations now, and I think it covers every key you can type on a normal keyboard now. Here it is.


Changes in version 0.3 (relative to the keymap in 0.1 below):

- left softkey is now "\"/"|"/"`"
- right softkeys are now "["/"{"/"<" and "]"/"}"/">"
- alt-z is now "^", since .com is tab now

Changes in version 0.2:
- modifications to the tools used in dumping keymaps and regenerating them

Changes in version 0.1:

- make ".com" a TAB key, as it ought to be
- make first right soft key "\" (shifted is "|")
- make second right soft key "<" (shifted is ">")

Installation instructions:

NOTE: I have not tested this on the Desire Z. I have no idea what its keycharmap and keylayout files look like.
FURTHER NOTE: Use at your own risk, etc, etc. I've included the original keymap files in the .zip as (filename).orig, but it can't hurt to take your own backups
FURTHER FURTHER NOTE: I've only tested version 0.3 on Cyanogenmod 6.1-RC1 on my G2, but there's no reason it shouldn't work on stock or an alternate ROM, since the keycodes I'm actually using should be the same.


PREREQUISITES: S-OFF G2, /system mounted read-write, root, busybox for 'cp'

- download file
- unzip g2-keymap-0.3.zip
- $ adb push vision-keypad.kl /sdcard
- $ adb push vision-keypad.kcm.bin /sdcard
- $ adb shell
- $ su # (if you don't have ro.secure turned off)
- # cp -f /sdcard/vision-keypad.kl /system/usr/keylayout/
- # cp -f /sdcard/vision-keypad.kcm.bin /system/usr/keychars/
- # reboot

To uninstall, just copy the .orig files back into place (so, copy vision-keypad.kl.orig to /system/usr/keylayout/vision-keypad.kl and vision-keypad.kcm.bin.orig to /system/usr/keychars/vision-keypad.kcm.bin

Hope you find this useful!

You can find the tools I used for dumping keymaps and the keymap files themselves with history on my github at https://github.com/aglasgall/g2-keymap
 

Attachments

  • g2-keymap-0.3.zip
    2.9 KB · Views: 1,267
Last edited:

mikeybot

Senior Member
Nov 28, 2008
85
7
philly
OnePlus 9
Just out of fear of screwing my phone up, on the cp I'm getting:
cp: can't create '/system/usr/keylayout/vision-keypad.kl': File exists

How should I proceed from here?
 

teferi

Member
Oct 1, 2010
28
6
Should have remembered that busybox cp refuses to overwrite files without -f. Use 'cp -f'; I'll update the instructions.

Thanks for the catch!
 

funkeee

Senior Member
May 25, 2010
292
13
So the soft keys are quick keys? I thought the Home, Menu, etc are soft keys.

I really felt like remapping the left-most quick key to alt, because that's where I'm used to having it.

I think each person may feel differently about the quick keys. Is it possible you could make a customizable version of your keymap? That would be superb. In the meantime I'll check this out, because I don't use those quick keys. Thanks.
 

teferi

Member
Oct 1, 2010
28
6
Yes, by "soft keys" I meant the shortcut keys. I could conceivably write a tool to generate customized keychar maps and keylayout maps, and maybe I will this weekend considering the long train rides I have ahead of me, but frankly it would be a lot of work and this particular itch is scratched for me, so I wouldn't get my hopes up were I you ;)

If you're interested in editing these yourself, you'll need the following:

1) the tool 'evtest' to get keyboard scancodes
2) the Input Devices section of the Android porting guide at http://source.android.com/porting/index.html (though n.b. that a distressing amount of it is inaccurate)
3) base keylayout and keycharmap files (pull 'em off your device)
4) a keycode to keycode label translation table (there's one in the AOSP tree at frameworks/base/include/ui/KeycodeLabels.h; n.b. that it is INCOMPLETE and doesn't cover all the keycodes the G2's keylayout map generates!

Keyboard input on Android works like this:

scancodes from Linux input core (on the G2, the keyboard is /dev/input/event5) -> scancode to keycode translation (via the .kl keylayout map) -> keycode to character translation modified by any active modifiers (alt/shift/alt+shift)

You'll find the KeyLayoutMap and KeyCharacterMap classes in frameworks/base/libs/ui/ very helpful. I have a tool knocked up out of KCM to generate dumps of the compiled .kcm.bin files which I'm happy to share.

Happy hacking!
 

misteropinion

Senior Member
Jun 2, 2009
85
5
Yes, by "soft keys" I meant the shortcut keys. I could conceivably write a tool to generate customized keychar maps and keylayout maps, and maybe I will this weekend considering the long train rides I have ahead of me, but frankly it would be a lot of work and this particular itch is scratched for me, so I wouldn't get my hopes up were I you ;)
This also scratched my itch. I mean, how can you do anything without | ?

Thanks bunches, man!
 

EMERYfan1988

Senior Member
May 9, 2008
55
3
what we need is when you long press the number key on the physical keyboard it gives you the option for the number. Kinda like HTC_IME keyboard. I keep getting confused when i switch between the two.
 

tornado9015

Member
Oct 29, 2010
24
1
what we need is when you long press the number key on the physical keyboard it gives you the option for the number. Kinda like HTC_IME keyboard. I keep getting confused when i switch between the two.

That would be a lot more complicated than a simple remapping. But I agree, if you use both the touch and physical keyboard, it is easy to get annoyed at the need to press alt key for numbers. They really should have had a number row, I used to love my sidekick's keyboard so much. Crappy phone though.
 

oldsk00lz

Senior Member
Nov 14, 2008
233
14
After some quality time with the AOSP source and a hex editor today, I've come up with modified keymap files for the G2 that make the keyboard a bit more useful. Here it is.
...
Hope you find this useful!

Nice! I saw you on #g2root digging for this info, so I'm glad you pulled it together.

Will have to check out since the long presses don't work in a terminal, and slow the process down anyway. We really needed |, <, and >. Also dedicated tab versus alt-z is nice.

Hahaha, just hit my quick keys to see what I had programmed in (telnet, Notes Everywhere, and Shazam) since it had been so long. I seldom open the keyboard to actually use these.

-oldsk00lz
 

aeidian

Senior Member
Oct 21, 2010
152
25
What's the likelyhood of getting some kind of graphical remake of the virtual qwerty? I really just want the spacebar to be a tad bit bigger height wise. I keep hitting the damn b key when I want to space because of the wrap around case. Is this even possible to do?
 

teferi

Member
Oct 1, 2010
28
6
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.
 

ratchetrizzo

Senior Member
Jun 3, 2010
578
63
Newark, DE
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.

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!
 

spullar

Member
Aug 17, 2009
11
0
That would be a lot more complicated than a simple remapping. But I agree, if you use both the touch and physical keyboard, it is easy to get annoyed at the need to press alt key for numbers. They really should have had a number row, I used to love my sidekick's keyboard so much. Crappy phone though.

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.
 

dhkr123

Senior Member
Nov 8, 2010
290
15
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).
 

keenerb

Senior Member
Jan 30, 2008
212
7
Dude, where were you two weeks ago when I was trying to get keycodes to fix Dosbox???
 

teferi

Member
Oct 1, 2010
28
6
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.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 6
    After some quality time with the AOSP source and a hex editor today, I've come up with modified keymap files for the G2 that make the keyboard a bit more useful. It's gone through three iterations now, and I think it covers every key you can type on a normal keyboard now. Here it is.


    Changes in version 0.3 (relative to the keymap in 0.1 below):

    - left softkey is now "\"/"|"/"`"
    - right softkeys are now "["/"{"/"<" and "]"/"}"/">"
    - alt-z is now "^", since .com is tab now

    Changes in version 0.2:
    - modifications to the tools used in dumping keymaps and regenerating them

    Changes in version 0.1:

    - make ".com" a TAB key, as it ought to be
    - make first right soft key "\" (shifted is "|")
    - make second right soft key "<" (shifted is ">")

    Installation instructions:

    NOTE: I have not tested this on the Desire Z. I have no idea what its keycharmap and keylayout files look like.
    FURTHER NOTE: Use at your own risk, etc, etc. I've included the original keymap files in the .zip as (filename).orig, but it can't hurt to take your own backups
    FURTHER FURTHER NOTE: I've only tested version 0.3 on Cyanogenmod 6.1-RC1 on my G2, but there's no reason it shouldn't work on stock or an alternate ROM, since the keycodes I'm actually using should be the same.


    PREREQUISITES: S-OFF G2, /system mounted read-write, root, busybox for 'cp'

    - download file
    - unzip g2-keymap-0.3.zip
    - $ adb push vision-keypad.kl /sdcard
    - $ adb push vision-keypad.kcm.bin /sdcard
    - $ adb shell
    - $ su # (if you don't have ro.secure turned off)
    - # cp -f /sdcard/vision-keypad.kl /system/usr/keylayout/
    - # cp -f /sdcard/vision-keypad.kcm.bin /system/usr/keychars/
    - # reboot

    To uninstall, just copy the .orig files back into place (so, copy vision-keypad.kl.orig to /system/usr/keylayout/vision-keypad.kl and vision-keypad.kcm.bin.orig to /system/usr/keychars/vision-keypad.kcm.bin

    Hope you find this useful!

    You can find the tools I used for dumping keymaps and the keymap files themselves with history on my github at https://github.com/aglasgall/g2-keymap
    5
    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:
    Code:
    key 183   USER1            WAKE_DROPPED

    To this:
    Code:
    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:
    Code:
    # keycode      Display   Number    Base      Shift     Alt       Shift+Alt
    LEFT_BRACKET   '['       '['       '['       '{'       '['       '{'
    RIGHT_BRACKET  ']'       ']'       ']'       '}'       ']'       '}'

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

    Then you compile the modified kcm file using the kcm.exe utility
    Code:
    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)
    Code:
    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.
    1
    Thanks for your answer, but how I have to modify these files to have the "right" and "left" arrow functionality? and how the .bin file is supposed to be generated?
    I would like to modify them by myself, but i've tried without no success :/

    open vision-keypad-XX.kl file under /system/usr/keylayout

    find the scancode of the key you wanna map as left,right, change the keycode to "DPAD_UP"(left, as in landscape mode, Dpad up is left), or "DPAD_DOWN"(right)

    I've written a short guide here http://forum.xda-developers.com/showthread.php?t=945921
    however you don't have to modify kcm.bin for this remap
    1
    Fix for newer Builds

    Since around CyanogenMod Nightly 80, my keymapping did not work anymore. After some debugging, I found out that the system now attempts to load the files
    Code:
    vision-keypad-wwe.kl
    vision-keypad-wwe.kcm.bin
    instead of
    Code:
    vision-keypad.kl
    vision-keypad.kcm.bin
    (note the added '-wwe').
    After renaming the files, it works again.

    I also updated my German blog post with this information (see https://patrick-nagel.net/blog/archives/251 ), where I offer a modified keymap with German umlauts and various symbols.
    1
    Shift+Fn+A = ^

    What is the Fn key on the keypad and how would one activate the above key pattern? Do you press all the keys at the same time or one at a time in the above order left to right?

    Thanks

    I assume you have a US T-mobile G2? The FN key on Desire Z is Alt on G2.

    Also, to activate Shift+Fn+A, you can either press them at the same time, or one by one, or Shift+Fn together then A, or Shift then Fn+A, or Fn then Shift+A... :D