Search code examples
androidandroid-sourcekeyevent

Writing a Android System app that uses KeyEvents to insert text into a text field. But Extended unicode characters are not printable


So I could use a combination of CTL+ for control characters , SHIFT+ for Upper case letters like A ,B and characters like !,{ (i.e Basic Latin and punctuation characters) .

However I am not able to find the combination in Android for symbols like Ã,dž ... etc. Ubuntu Uses a combination of CTRL+SHIFT+U .. followed by four numbers that generate the symbol, but that does not seem translatable to Android.

TL;DR : How to generate special symbols using Android KeyEvents and KeyCharacter Map?

Update : Learnt about this resource : https://source.android.com/devices/input/key-character-map-files and it looks like I will have to use a key combo and they talk about a magic hex input , but I have tried using

1111 followed by Alt+Shift+X ( qwerty.kcm file contains this) ... But it does not type out the unicode symbol to the corresponding 1111.

Can someone help with this please ?


Solution

  • Was able to figure it out .

    Step 1 : Update your Android OS's kcm file (most of the cases its Generic.kcm) . The example below is with the "X" button but it can be applied to any button really . Add the alt+shift behavoir and assing the magic hex code to the combination of alt+shift+X.

    key X {
        label:                              'X'
        base:                               'x'
        shift, capslock:                    'X'
        alt+shift:                          '\uef00'
    }
    

    Step 2: Generate Keyevents for 1,2,3,4 followed by a keyevent for Alt+Shift+X in your applications service and you will be able to print the character "ሴ" .

    Read these Resources for further information.

    https://source.android.com/devices/input/key-character-map-files
    https://developer.android.com/reference/android/view/KeyEvent
    https://android.stackexchange.com/questions/38405/how-to-insert-unicode-characters-by-their-hex-codes-using-usb-keyboard-on-ics