Issue
I've been trying to program my own keyboard on android using android studio. One thing I wanted to add are some arrow keys to move the cursor. My current code for the layout of the keyboard follows this format
<Row>
<Key android:keyLabel="..."
android:keyEdgeFlags="left"
android:codes="..."/>
<Key android:keyLabel="..."
android:codes="..."/>
<Key android:keyLabel="..."
android:keyEdgeFlags="right"
android:codes="..."/>
</Row>
and so on.
I'm not familiar with the android:codes. I understand that you're supposed to put the html code or the decimal value of unicode characters, and keyboard functions like enter or delete have negative values, like -4 or -5, but I don't really know what negative number corresponds to what function. I can't really find it online. Essentially, I'm not sure if I can move the cursor with android:codes or if I need to use something else to do it.
Solution
First off- I wouldn't be using this approach at all. KeyboardView is deprecated. The reason is that no serious keyboard uses it (not even Google's own), so they decided not to maintain it further.
Secondly- I don't think you can do that via this method. Codes are unicode characters. Unicode doesn't have cursor movement commands. Unicode doesn't have the concept of a cursor. You could easily do this via InputConnection calls (get the selection, alter it, then set the selction), for left and right, but not via unicode characters. You'd need to set those keys to call a function, which I'm not sure if KeyboardView can do.
Third- up and down keys will be almost impossible to do. The reason is word wrapping. You have no idea where the word wrapping linebreaks will occur, so figuring out where 1 line down is will be next to impossible. The only thing that could really do that is the view itself, and there's no support for that in EditText. Your best bet here would be to send a KeyEvent with a KEYBOARD_DPAD_UP or KEYBOARD_DPAD_DOWN and hope it works).
(Also, enter and delete aren't negative codes. Enter is a '\n' character, and has a value. Same for delete. But none of them have negative values).
Answered By - Gabe Sechan
Answer Checked By - Gilberto Lyons (JavaFixing Admin)