How to handle multi-keycode keys on Android with a bluetooth keyboard? - General Questions and Answers

I have a Microsoft Mobile Wedge keyboard. I've connected it to my Nexus 9 and after setting the language in the settings it works almost perfectly. Almost!
There are 4 keys on it that don't work, because they're multi-keycode keys. They're the "magnifier glass"-key, the "3 dots on a ring"-key, the "black rectangle intersecting with rectangle border"-key and the "gears/settings"-key.
So far I've found out with
Code:
getevent -lt /dev/input/event4
that the Linux keycodes they send are
Code:
KEY_LEFTSHIFT
KEY_LEFTMETA
KEY_F21
Code:
KEY_LEFTALT
KEY_LEFTMETA
KEY_F21
Code:
KEY_LEFTCTRL
KEY_LEFTMETA
KEY_F21
Code:
KEY_LEFTMETA
KEY_F21
I've created the 2 files
Code:
/system/usr/keylayout/Vendor_045e_Product_0790.kl
/system/usr/keychars/Vendor_045e_Product_0790.kcm
and made sure with
Code:
dumpsys input
that they're used.
I tried to enable the F21 in the layout first, but that didn't work because there's no Android keycode for F21. So I bound it to INSERT instead, because it's an unused key.
Then I went into the character map and tried making an INSERT key (which is actually F21) and apply the right modifiers to it.
Code:
key INSERT {
base: 'a'
lmeta: 'A'
}
The above being for the key that only had 2 keycodes. Unfortunatley this didn't work. Nothing happened. So now I'm here to pick your brain.
Does anyone know how to do multi-keycode keys?
Thank you very much in advance.

Related

Adding & mapping SPECIAL_FUNCTION keys

I'm getting on customizing key shortcuts
source : http://source.android.com/tech/input/keyboard-devices.html
example
0x0055 KEYCODE_MEDIA_PLAY_PAUSE
so, if /system/usr/keylayout/Generic.kl
--- snip---
key 26 LEFT_BRACKET
--- snip---
change to
--- snip---
key 26 MEDIA_PLAY_PAUSE
--- snip---
left bracket act as play/pause. But where is this action mapped? Hardcoded somewhere?
also, reading docs appears to be possible to add more of these SPECIAL_FUNTION keys, but only few of the actuals really works (i.e. MUSIC doesn't work). Also bind keycode to services seems to work only with certain kernels
init.rc
Code:
service key1 /system/bin/key1
oneshot
disabled
keycodes 26

[root]Alternative keyboard layout compilation

Hi there,
as this phone isn't available outside of the US I guess it's convenient for us importers to have some keyboard layouts to choose from. I just made a german one - I've made a list with those layouts which were already mentioned somewhere in this forum.
German Layout
Download keypad files here
Code:
My changes:
- AT is now the Umlaut special character (eg. press AT, then 'a' to get 'ä')
- AT is bound to the EMAIL key (EMAIL + A/U/O for umlauts works pretty well)
- SEARCH is bound to the CONTACTS key
- ALT is also bound to the VOICESEARCH key
- Y is Z; Z is Y
- ALT + B will now result in 'ß'
I just got used to two ALT buttons (coming from the DZ/G2). The SEARCH button is used in some apps, but not very often.. I like to have it on my keyboard, thus binding it to the CONTACTS key (I use search+'x' for certain shortcuts).
Nordic layout
user032 said:
Here's a Nordic layout I'm using. It should cover Swedish and Finnish characters. The keymaps have been shamelessly ripped off Desire Z CyanogenMod configuration files.
Email = Ö
Messaging = Ä
Voice Search = Å
sec_keypad.kl:
Code:
# Problem Children
key 155 BUTTON_4 WAKE_DROPPED
key 429 BUTTON_5 WAKE_DROPPED
key 217 BUTTON_3 WAKE_DROPPED
sec_keypad.kcm:
Code:
key BUTTON_3 {
label:'\u00C5'
base:'\u00E5'
shift, capslock:'\u00C5'
alt: '\u00E5'
shift+alt:'\u00C5'
}
key BUTTON_4 {
label:'\u00D6'
base:'\u00F6'
shift, capslock:'\u00D6'
alt: '\u00F6'
shift+alt:'\u00D6'
}
key BUTTON_5 {
label:'\u00C4'
base:'\u00E4'
shift, capslock:'\u00C4'
alt: '\u00E4'
shift+alt:'\u00C4'
}
Click to expand...
Click to collapse
jarrodlombardo's layout (Double [email protected]+DPAD_CENTER)
jarrodlombardo said:
Using the tips from http://forum.xda-developers.com/showpost.php?p=33762519&postcount=537 and some prior knowledge, I modified my keys so Irssi ConnectBot could work (it requires a DPAD_CENTER hard key) and some other things could be better.
If you replace your current versions with the below links, you'll get the following changes:
Shift + [number] gives the symbol Alt + [number] does.
The Email key will give you '@' and Alt + Email will give '~'. (This is how I had modified my Sidekick 4G's @ key since that kbd didn't have '~' at all.)
The stupid microphone button does DPAD_CENTER (this is the same as pressing the trackball button on phones that have them).
sec_keypad.kcm Put this in /system/usr/keychars/.
sec_keypad.kl Put this in /system/usr/keylayout/.
Click to expand...
Click to collapse
orange808's layout (multiple SEARCH keys)
orange808 said:
Sure. Here's my configuration:
http://www.mediafire.com/?tp3jc392w2q2jyg
The right shift key and the alt key are now search keys. This makes using quick launch keyboard shortcuts very easy because there are keys in both corners of the device to press--along with another key to launch an app. This eliminates the need to reach across the device when multitasking.
The voice key is now the right shift.
The sms/contacts and email buttons are now both alt keys.
It's not for everyone and most people will probably be confused with keys that perform strange actions (that conflict with their labels), but it works for me.
Click to expand...
Click to collapse
How to
(you need to mount the system partition as R/W to overwrite those files)
sec_keypad.kcm goes to /system/usr/keychars
sec_keypad.lk goes to /system/usr/keylayout
As written by dillalade in his post about keylayouts. Thanks to Nocturin for creating his information portal - which brought me there.
Feel free to upload your layout files / describe your changes - I'll add them to the list. They don't have to be language specific.
Just made some changes to my layout (added 'ß'), added two more (already mentioned) layouts.
Ctrl key.
Sory if this is not right section but I believe it is somehow related.
Is there a chance to add like or emulate key CTRL?
I was in shock when I get the mobile as was never thinking it is not present.
Regards
Mac
mazak23 said:
Sory if this is not right section but I believe it is somehow related.
Is there a chance to add like or emulate key CTRL?
I was in shock when I get the mobile as was never thinking it is not present.
Regards
Mac
Click to expand...
Click to collapse
Sure, since you can use normal keyboards with your android device there has to be some CTRL function - though I don't know why you'd want CTRL keys. There are some shortcuts in android which use CTRL similar to those windows has.. but I can't think of any other uses.
You just have to bind LEFT_CONTROL or RIGHT_CONTROL (in sec_keypad.kl) to any key you want. Haven't tested that though.
Kueber said:
Sure, since you can use normal keyboards with your android device there has to be some CTRL function - though I don't know why you'd want CTRL keys. There are some shortcuts in android which use CTRL similar to those windows has.. but I can't think of any other uses.
You just have to bind LEFT_CONTROL or RIGHT_CONTROL (in sec_keypad.kl) to any key you want. Haven't tested that though.
Click to expand...
Click to collapse
I want to use it for copy/paste options, we can do it on screen, but sometimes it's faster, and I prefer to do it with physical keyboard.
So do I have to root my device to change anything in that file, I am on 4.1.2 stock one now.
Thanks
Mac
Ah, I see - good idea actually, I'll try that.
Yes, you have to be rooted since you have to modify sytem files.
Sent from my SGH-T699
Kueber said:
Ah, I see - good idea actually, I'll try that.
Yes, you have to be rooted since you have to modify sytem files.
Sent from my SGH-T699
Click to expand...
Click to collapse
Recently I did ping in Shell apk and could't stop it, as without CTRL key I don't know how... So there is more than I said before.
Here's a Nordic layout I'm using. It should cover Swedish and Finnish characters. The keymaps have been shamelessly ripped off Desire Z CyanogenMod configuration files.
Email = Ö
Messaging = Ä
Voice Search = Å
sec_keypad.kl said:
# Problem Children
key 155 BUTTON_4 WAKE_DROPPED
key 429 BUTTON_5 WAKE_DROPPED
key 217 BUTTON_3 WAKE_DROPPED
Click to expand...
Click to collapse
sec_keypad.kcm said:
key BUTTON_3 {
label:'\u00C5'
base:'\u00E5'
shift, capslock:'\u00C5'
alt: '\u00E5'
shift+alt:'\u00C5'
}
key BUTTON_4 {
label:'\u00D6'
base:'\u00F6'
shift, capslock:'\u00D6'
alt: '\u00F6'
shift+alt:'\u00D6'
}
key BUTTON_5 {
label:'\u00C4'
base:'\u00E4'
shift, capslock:'\u00C4'
alt: '\u00E4'
shift+alt:'\u00C4'
}
Click to expand...
Click to collapse
Finally I made CONTROL key.
In file sec_keypad.kl I have now:
key 215 CTRL_LEFT
So instead of email key it is left control key.
I am so glad!
Now I am wondering how to add polish characters : ą, ć, ę, ł, ń, ó, ś, ź, ż
They should be under adequate letter and CTRL button (I believe).
Anybody can point me in the right direction?
Kueber said:
Hi there,
as this phone isn't available outside of the US I guess it's convenient for us importers to have some keyboard layouts to choose from. I just made a german one - I've made a list with those layouts which were already mentioned somewhere in this forum.
...
// edit: I forgot the 'ß', lol. I bound it to alt+B, since this button has no alt function + minor thread layout changes, added two more mappings which were mentioned in Nocturin's post
Click to expand...
Click to collapse
*I want to follow you with my layout but cannot found ß symbol in files you are posting.
Can you update files?
Thanks
mazak23 said:
*I want to follow you with my layout but cannot found ß symbol in files you are posting.
Can you update files?
Thanks
Click to expand...
Click to collapse
It's in the sec_keypad.kcm:
Code:
key B {
label: 'B'
number: '2'
base: 'b'
shift, capslock: 'B'
alt: '\u00df'
shift+alt, capslock+alt: '\u00df'
\u00df is unicode for 'ß'.
Kueber said:
It's in the sec_keypad.kcm:
Code:
key B {
label: 'B'
number: '2'
base: 'b'
shift, capslock: 'B'
alt: '\u00df'
shift+alt, capslock+alt: '\u00df'
\u00df is unicode for 'ß'.
Click to expand...
Click to collapse
Yeah , right.
Silly me, I was looking for S sharfe itself, it is unicode UTF 8?
Yup, UTF 8. DF is 223 in decimal. There are tables out there with all the special keys and their HTML-decimal value.
Here is polish keyboard layout.
Mainly we are getting special letters with CTRL button (which is under email key), but some are coming with left ALT. Thus because CTRL + C for example is COPY.
More explained in files.
Soon I will do it with right shift, which I see useless at all.
Pretty interesting this thread.
I just bought one of these best qwerty device masterpiece and I'm start wondering about how to make special CZECH characters under the numbers 2-0
I'd like this:
2 = ě
3 = š
4 = č
5 = ř
6 = ž
7 = ý
8 = á
9 = í
0 = é
Can you guys give me some guide? Many thanks in advance!
Is it no better to do it with alt or ctrl key?
Kueber wrote already instruction on next post.
There is one thing we should remember, permissions.
I experienced that when it is not right Android is using different file for keyboard layout (not using file sec_keypad.kcm).
I believe it is OK to use Root Explorer apk as it was mention somewhere.
Regards
xheretic said:
Pretty interesting this thread.
I just bought one of these best qwerty device masterpiece and I'm start wondering about how to make special CZECH characters under the numbers 2-0
I'd like this:
2 = ě
3 = š
4 = č
5 = ř
6 = ž
7 = ý
8 = á
9 = í
0 = é
Can you guys give me some guide? Many thanks in advance!
Click to expand...
Click to collapse
You have to modify the sec_keypad.kcm - just edit the keys.
For example, find the '2' key and edit the 'ě' in.. but you need to write it in UTF8.
1) Find character ascii value: ě -> 277 I believe (you can find those numbers in any ASCII chart <- this one even displays all the values in hex)
2) convert to HEX: 115
3) ě in unicode is now '\u0115' - just put the hex-number in like I did
4) edit the value in sec_keypad.kcm
Should look like this:
Code:
before
key 2 {
label: '2'
number: '2'
base: '2'
shift: '2'
alt: '@'
shift+alt: '@'
}
after
key 2 {
label: '2'
number: '2'
base: '\u0115'
shift: '2'
alt: '@'
shift+alt: '@'
}
Now "2" will result in a "ě" .. shift+2 will be your regular "2". Hope that helps.
my own polish physical keyboard layout and char map:
http://forum.xda-developers.com/attachment.php?attachmentid=2293495&stc=1&d=1380569369
voicesearch key (the stupid microphone) mapped to ALT_RIGHT
'ć', 'ę', 'ł', 'ń', 'ó', 'ś', 'ź', 'ż' under right alt+c, e, l, n, o, s, x and z key, respectively
'ą' is under right alt+q key, i could not make it work with a
e-mail key mapped to CTRL_LEFT, crtl+c and ctrl+v shortcuts work
i also recommend this:
http://source.android.com/devices/tech/input/key-character-map-files.html
to everyone making custom keyboard layouts. it explains *.kcm files well
i would like to thank kueber, dillalade and mazak23
good to see that i am not the first t699 user in poland
So, who wants to kang this for us? https://github.com/CyanogenMod/andr...mmit/7f6a2c6a56aceca8505cfce97c5a2cf77612a791
Alternatively, if we set this up, would people submit keymaps for various languages?
Nardholio said:
Alternatively, if we set this up, would people submit keymaps for various languages?
Click to expand...
Click to collapse
feel free to use mine and modify it in any way you like

[GUIDE] How to get good Ctrl and Alt keys in SSH while keeping Fn

Hi folks. I use JuiceSSH. In the current CM settings, it interprets the hardware alt key as an actual console alt. This is nice for changing windows in irssi (Alt+1, Alt+2, ...), but it's not useful for getting at the Fn keys for special characters. It would be nice to have Fn, Ctrl, and Alt, all working. Here's how to get this done:
View this: hxxp://data.zx2c4.com/galaxy-relay-keyboard-map.jpg
The file /system/usr/keylayout/sec_keypad.kl contains correlations of keycodes and keychars. It turns out JuiceSSH interprets ALT_LEFT as console alt, ALT_RIGHT as Fn, and CTRL_LEFT as console ctrl. So in that file, we want to remap ALT_LEFT to ALT_RIGHT, and then remap the MAIL and CHAT keys to CTRL_LEFT and ALT_LEFT respectively:
Code:
key 56 ALT_RIGHT WAKE_DROPPED
key 155 CTRL_LEFT WAKE_DROPPED
key 429 ALT_LEFT WAKE_DROPPED
key 217 META_LEFT WAKE_DROPPED
The full keycode file is available at hxxp://data.zx2c4.com/sec_keypad_modified.kl .
Here's a command listing of how I enable this using adb:
Code:
[email protected] ~ $ adb shell
[email protected]:/ $ su
[email protected]:/ # mount -o rw,remount /system
[email protected]:/ # wget -O /system/usr/keylayout/sec_keypad.kl hxxp://data.zx2c4.com/sec_keypad_modified.kl
[email protected]:/ # reboot
In practice, this thus far works very well.
Remember to change "hxxp" in this post; as a new member of XDA, I'm not allowed to post links.
I don't use JuiceSSH (but I'll definitely try it at some point if only for mosh), so I tried that with the built-in terminal app. By the way I don't know what version of CM 10.2 you're using, but here on the 20130909 nightly I found the kymaps in /system/usr/keylayout and not in /system/usr/keymap.
I didn't remap ALT_LEFT, but did remap 155 to CTRL_LEFT and 429 to META_LEFT like you did. I also remapped 217 to ESCAPE which is very handy in vim. Here's the diff:
--- sec_keypad.kl.orig 2013-09-12 17:55:28.434192677 -0600
+++ sec_keypad.kl 2013-09-12 18:12:08.876521089 -0600
@@ -81,3 +81,3 @@
-key 155 ENVELOPE WAKE_DROPPED
-key 429 CONTACTS WAKE_DROPPED
-key 217 SEARCH WAKE_DROPPED
+key 155 CTRL_LEFT WAKE_DROPPED
+key 429 META_LEFT WAKE_DROPPED
+key 217 ESCAPE WAKE_DROPPED
The ESCAPE works but not the CTRL_LEFT and META_LEFT. The remapping does seem to work since the keys don't do any longer what they used to do. So I'm guessing it's the key compositing that doesn't work.
I'll keep looking.
Calchan said:
I found the kymaps in /system/usr/keylayout and not in /system/usr/keymap.
Click to expand...
Click to collapse
Typo! My bad; fixed above.
Calchan said:
ESCAPE which is very handy in vim.
Click to expand...
Click to collapse
That does indeed seem quite handy. I'm tempted to remap the mic button away from META how it is now (which is a bit useful but not super) and toward escape for vim. Good idea.
Having a working ctrl and alt key for android itself, not just the terminal, is proving invaluable. Ctrl+A, ctrl+C, ctrl+V, alt+left, alt+shift+left, etc -- all really nice to have when editing text.
You will most likely have to recompile the kernel to change those to alt and ctrl keys. The keys are laid out in board-apexq.c and they are mapped with standard linux keycode names from input.h.
Nardholio said:
You will most likely have to recompile the kernel to change those to alt and ctrl keys. The keys are laid out in board-apexq.c and they are mapped with standard linux keycode names from input.h.
Click to expand...
Click to collapse
I didn't have any such problem, and just changed the keycode association in the .kl file.
zx2c4 said:
That does indeed seem quite handy. I'm tempted to remap the mic button away from META how it is now (which is a bit useful but not super) and toward escape for vim. Good idea.
Click to expand...
Click to collapse
Key 214 is indeed the microphone key, and having that mapped to ESCAPE like I did is very handy. What is META used for?
Can you please try the CTRL and ALT keys in the defaut CM terminal and tell me if they work for you? I haven't had time yet to try in JuiceSSH yet, but they don't work in the default terminal here.
cm 10.2
To make the ALT keys work as described in cm 10.2, you need to delete /system/usr/idc/sec_keypad.idc .
I've found a more careful change, submitted here:
hxxp://review.cyanogenmod.org/#/c/53130/
I used your fix to make JuiceSSH working on my Relay (yes i bought one only for the keyboard/ssh - can't do that on my expensive N5)
It looks like the arrow keys are mapped 'backward' and some alt-<combination> keys (like the '.com') arn't working, is this correct?
[edit]
I fixed it (or it has been fixed by updating to a newer nightly of CM11). But I did also remove the 'idc' file as suggested in this thread, by placing it back things seemed to work correctly (the arrow keys)
[/edit]
I also had to edit Generic.kl.
how to edit system files?
I cant do it even though i have root and es file explorer has access to root ;/
help
EDIT:
Got it
Is ADB process required? or can i just reboot ?

Location "recent apps" button in .kl file

Hi, after determining the protocol to change the keyboard layout thanks to user birdie in this post, I remain unable to disable/remap my "recent apps" button in the navigation bar. (Another way to reach that goal would be the gravity box requires Xposed framework which is not yet compatible with my phone/firmware.)
For completeness:
Android 7.1.2
LineageOS version: 14.1-20180609-NIGHTLY-osprey
Phone: MotoG3.
In the original post referred to above, the recent button is said to be found in file
Code:
/system/usr/keylayout/synaptics_dsx.kl
However, that file does not exist (in that location) on my phone. The only two files that do exist are:
Code:
Generic.kl
AVRCP.kl
Hence I inspected both, and modified Generic.kl to
Code:
key 580 BACK VIRTUAL
key 581 HOME VIRTUAL
key 582 HOME VIRTUAL
So to be explicit, I remapped the "recent apps" button mapping, to home. However, it does not have any effect, neither after rebooting. Therefore, I have the following question:
Does anyone know in which file and under which key number the "recent apps" button is mapped, for the phone as detailed above?
Kind regards

[TUTORIAL] External keyboard remapping without root [4.1+]

There is a great post about external keyboard remapping [TUTORIAL] External keyboard remapping [3.0+] but it's requires root access. You should read it first to get a general idea about external keyboard remapping.
Since Android 4.1 an app can provide additional keyboard layouts (Key Character Map files). After installation they can be found at Settings -> Language & input -> Physical keyboard (the exact path may vary).
As we already know from the previous tutorial, there are two types of files to customize a keyboard layout: Key Layout files and Key Character Map files. But there is an undocumented feature: it's possible to have KL-mappings in KCM-file! To do this we just need to add map before each KL-mapping.
Code:
# KeyboardLayout.kl
# Swap CapsLock and Left Ctrl
key 58 CTRL_LEFT
key 29 CAPS_LOCK
# KeyCharacterMap.kcm
# Do the same but in KCM-file
map key 58 CTRL_LEFT
map key 29 CAPS_LOCK
So we can to remap an external keyboard by installing an app! No root required!
But how to get such app? There are several ways:
1. Install an existing one.
2. Build it yourself.
3. Build with a tool.
Install an existing one​There aren't many apps I'm aware of. One of them is More Physical Keyboard Layouts (Google Play | GitHub). It has a lot of different layouts for different languages but can't customize the mappings.
Build it yourself​The most complicated way. It requires a knowledge in Android app development.
Take a look at More Physical Keyboard Layouts source code or Custom Keyboard Layout source code.
First of all you need to specify a receiver in AndroidManifest.xml file:
XML:
<receiver
android:name=".InputDeviceReceiver"
android:label="@string/keyboard_layouts_label">
<intent-filter>
<action android:name="android.hardware.input.action.QUERY_KEYBOARD_LAYOUTS" />
</intent-filter>
<meta-data
android:name="android.hardware.input.metadata.KEYBOARD_LAYOUTS"
android:resource="@xml/keyboard_layouts" />
</receiver>
And you don't even need to create the corresponding InputDeviceReceiver.java in the souce code .
After that add the corresponding keyboard_layouts.xml file in app/src/main/res/xml . For example
XML:
<?xml version="1.0" encoding="utf-8"?>
<keyboard-layouts xmlns:android="http://schemas.android.com/apk/res/android">
<keyboard-layout
android:name="keyboard_layout_en_us"
android:keyboardLayout="@raw/keyboard_layout_en_us"
android:label="@string/keyboard_layout_en_us_label" />
<keyboard-layout
android:name="keyboard_layout_ru"
android:keyboardLayout="@raw/keyboard_layout_ru"
android:label="@string/keyboard_layout_ru_label" />
</keyboard-layouts>
That file contains a list of your keyboard layouts. They are just plain KCM-files that you should put in app/src/main/res/raw.
Build with a tool​If you don't want to build it yourself there is ExKeyMo web app (NOT AVAILABLE ANYMORE - you'll have to run it locally. Visit project's GitHub page for details). Just enter the content of your KCM-file in the ExKeyMo's form and click Download. It will build the app for you.
There is a web-version of validatekeymaps tool if you need to check your .kcm file.

Categories

Resources