[HTC Vivid, Raider, Velocity] drbortel:
Hello,

I didn't know if there was already a post for this, my searches were coming up not matching anything.

If you happen to have an external keyboard (bluetooth in my case), you might have the problem that many of the key events from the keyboard do not map nicely to the HTC Vivid. I am running 4.0.3 in my case with 3.6 sense, and other than the alpha-numerics, many of the system level keys were not working for me. Since I often play HD video from my phone to the HDTV, it's handy for me to control things like Volume_UP/Down, HOME / MENU / BACK, Pause / Play, Select Movie title, reply to Text, etc. So I had to find a way to improve the keyboard mappings to make it functional, and I was curious if others may have done similar things as what I describe here. I am still stuck on a few mappings, so would glad to have any info from others who have succeeded or failed in a similar regard.

I went and spent about $35 for this G-Cube bluetooth keyboard model BK-30 at Frye's.

h t t p :// www .gggcube .com/ Upload/ ProImgs/ smaImg/ 201303101915016774.jpg

It was a nice weight with a good feel on the keys, and good enough for a test run. The bluetooth device was discovered and paired easily on my HTC Vivid, and some of the system functions from keyboard were working, like Volume UP/Down and Mute. But I noticed right away I had no way to open a MENU option, or to perform a BACK function from a given application or settings screen. In order to change the keyboard mappings, it's necessary to boot into Recovery, un-mount /system and use ADB to re-mount /system in order to be able to edit the file called Generic.kl (keyboard layout file) which lives in the /system/usr/keylayout/ directory. Here are the steps I used to update the file.

Before editing the Generic.kl file, it's helpful to gather some information using an APP called KeyEvent Display (free in Google Play store).

1. Download, Install and Run the KeyEvent Display application, it gives you a keyEvent monitor for the Bluetooth Keyboard

2. Pick a few keys on the Bluetooth which seem to do nothing, and press them, noting their SCANCODE values in the app. I chose the PrintScr, Pause/Break, Insert and Delete keys, just as a test. These 4 keys gave me scancodes of 99, 119, 110, and 111, respectively.

Now, you can reboot the phone into Recovery, and perform operations using ADB, providing your PC has the right USB drivers. Usually installing HTC Sync will give you these drivers, or from Ubuntu Linux, you may not need them. Google to install the ADB tool

1. Make sure your Vivid is rooted with a Recovery Image for bootup

2. Boot into Recovery, Connect your USB cable from the PC, and test that your ADB tool can properly communicate:

a) to use ADB, you need to have download these files (adb.exe, AdbWinApi.dll and AdbWinUsbApi.dll)

b) from the directory where you have ADB, test the connection with a simple 'adb devices'

c) you should get a response from the phone device like this:

3. Assuming you are successful, you can now send ADB commands to the phone as needed here below. (If you got nothing after List of devices attached, you can research this seperately - its usually and USB driver issue.) ADB commands are used to mount and unmount file systems (like /system), to send commands or open a shell to the phone, and to push and pull files back and forth.

a) adb remount (should see: remount succeeded)

NOTE: if this fails with an error, use your Recovery Developer options to un-mount /system first, then try again.

b) adb pull /system/usr/keylayout/Generic.kl

NOTE: Generic.kl is the file we want with all the mappings of keyEvents. If the file is pulled successfully, you see something like:

c) Note with File Explorer in the folder with ADB, you should have a copy of the Generic.kl file.

d) Make a backup of this file, you can cause the keyboard and other items to fail with incorrect changes!

e) Edit the file with your favorite text editor, and look for sections that we want to change, for example:

f) Change keys 110 and 111 (for example) to now look like this, and then save the file:

g) adb push Generic.kl /system/usr/keylayout/ (this places the file back to the phone)

h) adb shell (need a shell to reset the permissions of the file)

i) chmod 644 /system/usr/keylayout/Generic.kl (should be read only to group/world)

j) ls -l /system/usr/keylayout/ (check to see ownership and permissions look correct)

k) exit (exit from the ADB shell)

l) adb reboot (reboot the phone out of recovery into normal mode)

3. Now when the phone is ready, test the new key functions you have defined. For me, I had success with the MENU, BACK, CALL and ENVELOPE functions, among others. It is very helpful that I can use ALT-TAB to toggle between running apps.

The main one which I am failing to define is the 'OPEN ALL APPS'. If anyone else is performing mappings such as these for an external bluetooth keyboard, I would be interested to know which functions you have gotten to work. I am now at a state where I can control most everything, provided it is already running in the background. But I can't swipe my Sense desktop left and right, and I have trouble toggling certain switches like Wifi and Mobile data. Any suggestions or thoughts on these functions are appreciated.

Darren

Troubleshooting TIP: You can also run ADB when the phone is running in Normal Mode and you have the USB cable connected from your phoe to the PC. Then you can test certain keypresses through functions that are formatted in this way:

On my phone, this function will send the CALL event with brings up the phone from the desktop.

Other examples (you can also launch then from a *.cmd file):

If you have a terminal open on the phone, will send "ls -l"(includes the space-62 and enter-66):

If you have a terminal open on the phone, will send "env|grep PATH":