1

I have been following this tutorial on making a custom keyboard. So far so good.

However, I wanted to know, is it possible to create a button to input predefined text. Eg. A button labeled "Name" which inputs the user's name? If it is possible, how do I do it? I have done extensive research, but can find nothing.

1 Answer 1

1

Yes, it's possible. In your implementation of InputMethodService define new keycode

private final static int NAME_CODE = -32; // value is absolutely random. The main requirement - there should not be coincidence with other codes

and later check for it in the onKey() method

@Override
public void onKey(int primaryCode, int[] keyCodes) {
    InputConnection ic = getCurrentInputConnection();
        switch(primaryCode){
        .....
        case NAME_CODE:
            ic.commitText(name, name.length());
            break;
        .....

And after that just use this code to bind special key from your Keyboard specification (qwerty.xml in example) and the logic.

<Key android:codes="-32" android:keyLabel="NAME" android:keyWidth="20%p" android:isRepeatable="true"/>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.