Android's InputMethodService - how to get unicode characters?

1

I'm trying to make a keyboard...

int code = 29; // Key code constant: 'A' key. Constant Value: 29 (0x0000001d)
KeyEvent k = new KeyEvent(KeyEvent.ACTION_UP, code);

InputConnection ic = getCurrentInputConnection();
ic.sendKeyEvent(k);

This code nicely send letter "A" to the application, as it is associated with the code "29", as from here http://developer.android.com/reference/android/view/KeyEvent.html

But what should I do, if I want to use unicode characters, such as in here
http://en.wikipedia.org/wiki/List_of_Unicode_characters

android
asked on Stack Overflow Aug 31, 2011 by Roger • edited Aug 31, 2011 by DonGru

2 Answers

0

If you are building a keyboard app, and have keyboard layout in xml, you can look at suggestion provided by user Laurent' in another thread:

<Key android:codes="946" android:keyLabel="\u03B2"/> 
<Key android:codes="946" android:keyLabel="&946;"/> 
<Key android:codes="946" android:keyLabel="β"/>  
<!-- Warning, you should use UTF-8 encoding for your project files if you use the third solution -->
<!-- all produce the same key with greek β character (unicode \u03B2, decimal 946) -->
answered on Stack Overflow Aug 17, 2015 by atabek • edited May 23, 2017 by Community
-1

Please check the softkeyboard sample code.

If you are developing a new keyboard(for example for any other language), change the android:code attribute value to the unicode value which you want the keyboard to output. This works fine and I think you can test it in the same softkeyboard project.

answered on Stack Overflow Aug 31, 2011 by swik

User contributions licensed under CC BY-SA 3.0