[G2 and Desire Z Android Development] zooid:
Barret7sc how exactly should I edit the unkcm.py to make it work for me? I am very desparate I have Toshiba AC100, but the keyboard layout isn't the way I am used to and the difference is absolute.

Unfortunately I am prevented from attaching a picture of the keyboard so you can find the layout by searching google. It is the BDS Bulgarian Keyboard Layout.

in directory /system/usr/keychars/ there are lots of kcm.bin files, but two of them are named qwerty.kcm.bin and qwerty2.kcm.bin. I guess one for each language, namely Bulgarian and English.

qwerty.kl looks like this:

key 399 GRAVE
key 2 1
key 3 2
key 4 3
key 5 4
key 6 5
key 7 6
key 8 7
key 9 8
key 10 9
key 11 0
key 158 BACK WAKE_DROPPED
key 230 SOFT_RIGHT WAKE
key 60 SOFT_RIGHT WAKE
key 107 ENDCALL WAKE_DROPPED
key 62 ENDCALL WAKE_DROPPED
key 229 MENU WAKE_DROPPED
key 139 MENU WAKE_DROPPED
key 59 MENU WAKE_DROPPED
key 127 SEARCH WAKE_DROPPED
key 217 SEARCH WAKE_DROPPED
key 228 POUND
key 227 STAR
key 231 CALL WAKE_DROPPED
key 61 CALL WAKE_DROPPED
key 232 DPAD_CENTER WAKE_DROPPED
key 108 DPAD_DOWN WAKE_DROPPED
key 103 DPAD_UP WAKE_DROPPED
key 102 HOME WAKE
key 105 DPAD_LEFT WAKE_DROPPED
key 106 DPAD_RIGHT WAKE_DROPPED
key 115 VOLUME_UP
key 114 VOLUME_DOWN
key 116 POWER WAKE
key 212 CAMERA

key 16 Q
key 17 W
key 18 E
key 19 R
key 20 T
key 21 Y
key 22 U
key 23 I
key 24 O
key 25 P
key 26 LEFT_BRACKET
key 27 RIGHT_BRACKET
key 43 BACKSLASH

key 30 A
key 31 S
key 32 D
key 33 F
key 34 G
key 35 H
key 36 J
key 37 K
key 38 L
key 39 SEMICOLON
key 40 APOSTROPHE
key 14 DEL

key 44 Z
key 45 X
key 46 C
key 47 V
key 48 B
key 49 N
key 50 M
key 51 COMMA
key 52 PERIOD
key 53 SLASH
key 28 ENTER

key 56 ALT_LEFT
key 100 ALT_RIGHT
key 42 SHIFT_LEFT
key 54 SHIFT_RIGHT
key 15 TAB
key 57 SPACE
key 150 EXPLORER
key 155 ENVELOPE

key 12 MINUS
key 13 EQUALS
key 215 AT

so I edited the unkcm.py like this

#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright (c) 2010 Alejandro R. Sedeño <asedeno@mit.edu>

# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation files
# (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:

# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from __future__ import with_statement
import sys
import struct
import StringIO

# All specified sources are from Google's Android SDK.
# For more information, see:
#

# kcm.bin file format
# Source:
# build/tools/kcm/kcm.cpp

# ***** HEADER *****
# Offset | Description
# 0x00-0x07 | The ascii value "keychar" including the null character
# 0x08-0x0b | Endian marker (0x12345678)
# 0x0c-0x0f | version (2)
# 0x10-0x13 | key count (n)
# 0x14-0x17 | keyboard type (NUMERIC [1], Q14 [2], QWERTY [3], etc.)
# 0x18-0x1f | Padding
# 0x20-.... | entries (16 bytes × key count)

# ***** ENTRIES *****
# Offset | Description
# 0x00-0x03 | KeyEvent name
# 0x04-0x05 | Display Label
# 0x06-0x07 | Number
# 0x08-0x09 | Base
# 0x0a-0x0b | Shift
# 0x0c-0x0d | Alt
# 0x0e-0x0f | Shift+Alt

# Keycode Labels
# source:
# frameworks/base/include/ui/KeycodeLabels.h
keycodes={"GRAVE": 399, "1": 2, "2": 3, "3": 4, "4": 5, "5": 6, "6": 7, "7": 8, "8": 9, "9": 10, "0": 11, "BACK": 158, "SOFT_RIGHT": 230, "SOFT_RIGHT": 60, "ENDCALL": 107, "ENDCALL": 62, "MENU": 229, "MENU": 139, "MENU": 59, "SEARCH": 127, "SEARCH": 117, "POUND": 228, "STAR": 227, "CALL": 231, "CALL": 61, "DPAD_CENTER": 232, "DPAD_DOWN": 108, "DPAD_UP": 103, "HOME": 102, "DPAD_LEFT": 105, "DPAD_RIGHT": 106, "VOLUME_UP": 115, "VOLUME_DOWN": 114, "POWER": 116, "CAMERA": 212, "Q": 16, "W": 17, "E": 18, "R": 19, "T": 20, "Y": 21, "U": 22, "I": 23, "O": 24, "P": 25, "LEFT_BRACKET": 26, "RIGHT_BRACKET": 27, "BACKSLASH": 43, "A": 30, "S": 31, "D": 32, "F": 33, "G": 34, "H": 35, "J": 36, "K": 37, "L": 38, "SEMICOLON": 39, "APOSTROPHE": 40, "DEL": 14, "Z": 44, "X": 45, "C": 46, "V": 47, "B": 48, "N": 49, "M": 50, "COMMA": 51, "PERIOD": 52, "SLASH": 53, "ENTER": 28, "ALT_LEFT": 56, "ALT_RIGHT": 100, "SHIFT_LEFT": 42, "SHIFT_RIGHT": 54, "TAB": 15, "SPACE": 57, "EXPLORER": 150, "ENVELOPE": 155, "MINUS": 12, "EQUALS": 13, "AT": 215}

rkeycodes={}
for (k,v) in keycodes.items(): rkeycodes[v] = k

keyboardTypes = {1: 'NUMERIC', 2: 'Q14', 3: 'QWERTY',}
def getKBType(n):
if n in keyboardTypes:
return keyboardTypes[n]
raise ValueError

MAGIC = 'keychar\x00'

def checkHeader(buf):
"""
Takes the first 32 bytes of the file, confirms it is a valid keymap header
Returns endian marker for struct, entry count, and keyboard type.
"""
(magic, marker) = struct.unpack('8s4s20x', buf)
if magic != MAGIC:
raise ValueError
endian = None
if marker == '\x12\x34\x56\x78': # big
endian = '>'
elif marker == '\x78\x56\x34\x12': # little
endian = '<'
else:
raise ValueError

(version, count, kbtype) = struct.unpack(endian+'12x3i8x', buf)
if version != 2:
raise ValueError
kbtype = getKBType(kbtype)
return (endian, count, kbtype)

class KR:
def __init__(self, values):
self.values = values
(self.keycode,
self.display,
self.number,
self.base,
self.shift,
self.alt,
self.shiftalt) = values

def __repr__(self):
return "KR: KeyCode %i; Base: %i" % (self.keycode, self.base)

def _fmt(self, val):
if 0x20 < val <= 0x7e:
return "'%s'" % chr(val)
else:
return '0x%X' % val

def printKR(self):
fmt = (rkeycodes[self.keycode],)
fmt += tuple([self._fmt(x) for x in self.values[1:]])
return ("%-15s%-10s%-10s%-10s%-10s%-10s%-10s" % fmt).strip()

def parseKR(buf, endian):
"""
Parses a 16-byte key row entry
"""
return KR(struct.unpack(endian+'I6H', buf))

def decompileKCM(In, Out):
header = In.read(32)
endian, count, ktype = checkHeader(header)
Out.write("[type=%s]\n" % ktype)
#------0 1 2 3 4 5 6 7
#------01234567890123456789012345678901234567890123456789012345678901234567890123
Out.write("# keycode Display Number Base Shift Alt Shift+Alt\n")
for i in range(count):
kr = parseKR(In.read(16), endian)
Out.write(kr.printKR()+"\n")

if __name__ == '__main__':
if len(sys.argv) != 3:
print ("""usage: kcm [INPUT] [OUTPUT]

INPUT compiled keycharmap file, - for STDIN
OUTPUT keycharmap file, - for STDOUT
""")
exit(-1)
In, Out = sys.argv[1:3]

output = StringIO.StringIO()
if In == '-':
decompileKCM(sys.stdin, output)
else:
with open(sys.argv[1],'rb') as f:
decompileKCM(f, output)

if Out == '-':
sys.stdout.write(output.getvalue())
else:
with open(sys.argv[2],'w') as f:
f.write(output.getvalue())

and KeycodeLabels.h like this:

/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef _UI_KEYCODE_LABELS_H
#define _UI_KEYCODE_LABELS_H

struct KeycodeLabel {
const char *literal;
int value;
};

static const KeycodeLabel KEYCODES[] = {
{ "GRAVE", 399 },
{ "1", 2 },
{ "2", 3 },
{ "3", 4 },
{ "4", 5 },
{ "5", 6 },
{ "6", 7 },
{ "7", 8 },
{ "8", 9 },
{ "9", 10 },
{ "0", 11 },
{ "BACK", 158 },
{ "SOFT_RIGHT", 230 },
{ "SOFT_RIGHT", 60 },
{ "ENDCALL", 107 },
{ "ENDCALL", 62 },
{ "MENU", 229 },
{ "MENU", 139 },
{ "MENU", 59 },
{ "SEARCH", 127 },
{ "SEARCH", 217 },
{ "POUND", 228 },
{ "STAR", 227 },
{ "CALL", 231 },
{ "CALL", 61 },
{ "DPAD_CENTER", 232 },
{ "DPAD_DOWN", 108 },
{ "DPAD_UP", 103 },
{ "HOME", 102 },
{ "DPAD_LEFT", 105 },
{ "DPAD_RIGHT", 106 },
{ "VOLUME_UP", 115 },
{ "VOLUME_DOWN", 114 },
{ "POWER", 116 },
{ "CAMERA", 212 },
{ "Q", 16 },
{ "W", 17 },
{ "E", 18 },
{ "R", 19 },
{ "T", 20 },
{ "Y", 21 },
{ "U", 22 },
{ "I", 23 },
{ "O", 24 },
{ "P", 25 },
{ "LEFT_BRACKET", 26 },
{ "RIGHT_BRACKET", 27 },
{ "BACKSLASH", 43 },
{ "A", 30 },
{ "S", 31 },
{ "D", 32 },
{ "F", 33 },
{ "G", 34 },
{ "H", 35 },
{ "J", 36 },
{ "K", 37 },
{ "L", 38 },
{ "SEMICOLON", 39 },
{ "APOSTROPHE", 40 },
{ "DEL", 14 },
{ "Z", 44 },
{ "X", 45 },
{ "C", 46 },
{ "V", 47 },
{ "B", 48 },
{ "N", 49 },
{ "M", 50 },
{ "COMMA", 51 },
{ "PERIOD", 52 },
{ "SLASH", 53 },
{ "ENTER", 28 },
{ "ALT_LEFT", 56 },
{ "ALT_RIGHT", 100 },
{ "SHIFT_LEFT", 42 },
{ "SHIFT_RIGHT", 54 },
{ "TAB", 15 },
{ "SPACE", 57 },
{ "EXPLORER", 150 },
{ "ENVELOPE", 155 },
{ "MINUS", 12 },
{ "EQUALS", 13 },
{ "AT", 215 },

// NOTE: If you add a new keycode here you must also add it to:
// (enum KeyCode, in this file)
// frameworks/base/core/java/android/view/KeyEvent.java
// tools/puppet_master/PuppetMaster.nav_keys.py
// frameworks/base/core/res/res/values/attrs.xml

{ NULL, 0 }
};

// These constants need to match the above mappings.
typedef enum KeyCode {
kKeyCodeGrave = 399,

kKeyCode1 = 2,
kKeyCode2 = 3,
kKeyCode3 = 4,
kKeyCode4 = 5,
kKeyCode5 = 6,
kKeyCode6 = 7,
kKeyCode7 = 8,
kKeyCode8 = 9,
kKeyCode9 = 10,
kKeyCode0 = 11,
kKeyCodeBack = 158,
kKeyCodeSoftRight = 230,
kKeyCodeSoftRight = 60,
kKeyCodeEndcall = 107,
kKeyCodeEndcall = 62,
kKeyCodeMenu = 229,
kKeyCodeMenu = 139,
kKeyCodeMenu = 59,
kKeyCodeSearch = 127,
kKeyCodeSearch = 217,
kKeyCodePound = 228,
kKeyCodeStar = 227,
kKeyCodeCall = 231,
kKeyCodeCall = 61,
kKeyCodeDpadCenter = 232,
kKeyCodeDpadDown = 108,
kKeyCodeDpadUp = 103,
kKeyCodeHome = 102,
kKeyCodeDpadLeft = 105,
kKeyCodeDpadRight = 106,
kKeyCodeVolumeUp = 115,
kKeyCodeVolumeDown = 114,
kKeyCodePower = 116,
kKeyCodeCamera = 212,
kKeyCodeQ = 16,
kKeyCodeW = 17,
kKeyCodeE = 18,
kKeyCodeR = 19,
kKeyCodeT = 20,
kKeyCodeY = 21,
kKeyCodeU = 22,
kKeyCodeI = 23,
kKeyCodeO = 24,
kKeyCodeP = 25,
kKeyCodeLeftBracket = 26,
kKeyCodeRightBracket = 27,
kKeyCodeBackslash = 43,
kKeyCodeA = 30,
kKeyCodeS = 31,
kKeyCodeD = 32,
kKeyCodeF = 33,
kKeyCodeG = 34,
kKeyCodeH = 35,
kKeyCodeJ = 36,
kKeyCodeK = 37,
kKeyCodeL = 38,
kKeyCodeSemicolon = 39,
kKeyCodeApostrophe = 40,
kKeyCodeDel = 14,
kKeyCodeZ = 44,
kKeyCodeX = 45,
kKeyCodeC = 46,
kKeyCodeV = 47,
kKeyCodeB = 48,
kKeyCodeN = 49,
kKeyCodeM = 50,
kKeyCodeComma = 51,
kKeyCodePeriod = 52,
kKeyCodeSlash = 53,
kKeyCodeEnter = 28,
kKeyCodeAltLeft = 56,
kKeyCodeAltRight = 100,
kKeyCodeShiftLeft = 42,
kKeyCodeShiftRight = 54,
kKeyCodeTab = 15,
kKeyCodeSpace = 57,
kKeyCodeExplorer = 150,
kKeyCodeEnvelope = 155,
kKeyCodeMinus = 12,
kKeyCodeEquals = 13,
kKeyCodeAt = 215
} KeyCode;

static const KeycodeLabel FLAGS[] = {
{ "WAKE", 0x00000001 },
{ "WAKE_DROPPED", 0x00000002 },
{ "SHIFT", 0x00000004 },
{ "CAPS_LOCK", 0x00000008 },
{ "ALT", 0x00000010 },
{ "ALT_GR", 0x00000020 },
{ "MENU", 0x00000040 },
{ "LAUNCHER", 0x00000080 },
{ NULL, 0 }
};

#endif // _UI_KEYCODE_LABELS_H

I don't know where do I go wrong but when I try to run unkcm.py it shows me this message:

Traceback (most recent call last):
File "D:\apps\Toshiba AC100\kcm_utils123456\toshiba_AC100_unkcm.py", line 29, in <module>
import StringIO
File "D:\apps\Toshiba AC100\kcm_utils123456\StringIO.py", line 40
raise ValueError "I/O operation on closed file"
^
SyntaxError: invalid syntax

perhaps I should mention that I've renamed unkcm.py to toshiba_AC100_unkcm.py

I'd really appreciate any help