4

I have created an input device driver that I use for controlling mouse/keyboard from an app. Everything works so far, I can generate input events for both keyboard and mouse from within the app.

The problem I'm facing right now is that I'm unable to enter special characters that are not on the keyboard. If I want to enter an eszett (ß), I can't just simulate a keypress for my input device.

If I'm not mistaken, key character map files should be able to fix this problem. I could map unicode characters to certain keys and then simulate a keypress for that key and the character would be entered.

I tried this, but it doesn't work and I don't understand why it doesn't work. I copied the Virtual.kcm file and renamed it to represent my devices vendor and product ID. To test, I replaced one line in the file to input an eszett instead of a '0' when the 0 key is pressed:

key 0 {
    label:         '\u00df'  // instead of '0'
    base:          '\u00df'  // instead of '0'
    shift:         ')'
}

I've made sure that the input device uses the correct kcm file by checking the output of 'dumpsys input':

6: custom-input
  Classes: 0x8000006b
  Path: /dev/input/event5
  Descriptor: ab3fb155bce23398b91099a8f37d5cae61f29d21
  Location: 
  UniqueId: 
  Identifier: bus=0x0003, vendor=0x1111, product=0x2222, version=0x0001
  KeyLayoutFile: /system/usr/keylayout/Vendor_1111_Product_2222.kl
  KeyCharacterMapFile: /system/usr/keychars/Vendor_1111_Product_2222.kcm
  ConfigurationFile: 
  HaveKeyboardLayoutOverlay: true

Everything looks fine so far, but when I actually generate an input event using sendevent, it still enters a '0' instead of an eszett.

sendevent /dev/input/event5 1 11 1  (KEY_EV, KEY_0, DOWN)
sendevent /dev/input/event5 0 0 0   (SYNC)
sendevent /dev/input/event5 1 11 0  (KEY_EV, KEY_0, UP)
sendevent /dev/input/event5 0 0 0   (SYNC)

I really expected this to work, but apparently it doesn't. Is there something I'm missing?

What would be the solution to enter unicode characters via an input device using kcm files (or in another way)?

Leon van Noord
  • 868
  • 1
  • 7
  • 24

2 Answers2

1

"Android does not currently support multilingual keyboards. Moreover, the built-in generic key character map assumes a US English keyboard layout.

OEMs are encouraged to provide custom key character maps for their keyboards if they are designed for other languages.

Future versions of Android may provide better support for multilingual keyboards or user-selectable keyboard layouts." extracted from https://source.android.com/devices/input/key-character-map-files.html#examples

Notice that in this fragment from the documentation it says that the OEMs are encouraged to provided custom key character maps. So this is a probable cause of your problem. It is possible that the OEM(original equipment manufacturer) of the device that you are using didn't implement custom multilinguald keyboard support. Since this is not required at this point it is possible that the mapping you want to do is not compatible with most devices since eszett is not part of the standard english keyboard, support for it should not be expected, with the exception that one of the OEMs have actually included support for this in their own implementations of the keyboard(remember that Google do not implements this, the OEM must do it).

Jorch914
  • 3,465
  • 2
  • 16
  • 21
  • In my particular case I am the 'OEM'. While there's no physical device involved, I wrote the driver for a virtual device. I did provide the key character map (the kcm file) for the device, but it doesn't do what it's supposed to do. I'm probably missing something. – Leon van Noord Sep 21 '15 at 07:39
  • I see, I don't think I can help with this one since I work in the hal layer (as OEM also) but now that you are telling me this, there might a possibility that the problem is related to the driver. Have you checked that the "virtual physical interface" you are using is not used by another driver? May be a long shot but I now several drivers in android are multiplexed, but some times due to bugs they interfere with each other. Anyway I have seen this happen a lot in android. But lack the experience to help you more with this. I do wish you luck and success with the issue. – Jorch914 Sep 21 '15 at 16:58
0

I figured out that if you select a keyboard layout different from "standard" in the settings, this layout overrides a kcm file. Even if this kcm file is listed in dumpsys input!

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Droidum
  • 440
  • 2
  • 9