I mostly fixed the problem with these lines in dispatchKeyEvent:
byte[] cmdLeft = { (byte) 27, (byte) '[', (byte) 'D' };
byte[] cmdErase = { (byte) 27, (byte) '[', (byte) 'P' };
mSession.appendToEmulator(cmdLeft, 0, cmdLeft.length);
mSession.appendToEmulator(cmdErase, 0, cmdErase.length);
The only problem now is that if I select the editText and hit delete then one character is deleted but two appear to be on screen. so if I write enable and hit delete it will change to enab but what would actually be sent is enabl
I overrode dispatchKeyEvent, and it kind of works. If the editText is selected, the terminal deletes characters over serial now, so that is a good step. However the main problem still exists that if the terminal is selected itself, weird little boxes are written to the screen instead of deleting a character. Well one is written, and if I keep pressing delete it stays at that one box, but next time I type the amount of deletes I pressed comes up as boxes. It's very odd...
It's like it is just overridden for the edittext and not for the terminal.
Weird little boxes in all their glory:
public boolean dispatchKeyEvent(KeyEvent event) {
if (event != null && event.getAction() == KeyEvent.ACTION_UP) {
return false;
}
if (event.getKeyCode() == KeyEvent.KEYCODE_DEL) {
try {
sendOverSerial("\b".getBytes("UTF-8"));
}
catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return super.dispatchKeyEvent(event);
};
I am connecting to a terminal emulator using a library in android, this connects to a serial device (a switch) and shows me sent/received data. I send data over the connection via a text box below the terminal or by typing in the terminal itself and hitting enter on the keyboard in both cases. It will only ever be a soft keyboard that is used. If I send an incorrect string I am in an unrecoverable state due to not having a delete key implementation. Backspace in my editTxt works fine, I just want it to work when the terminal is highlighted and I am writing in that.
At the moment if I press delete a little odd box character comes up and nothing else happens, I get an exception in the log some times(https://i.stack.imgur.com/xNyrZ.png). What I want to know is how to I go about changing the delete keys functionality so that when I press it I can send a delete character like this but also retain the ability to delete characters in the edittext box etc:
sendOverSerial("\b".getBytes("UTF-8"))
This sends a correct back space, I just need to incorporate it.
But the soft-keyboard doesn't seem to register key presses? i keep getting a keycode of 0 and only enter will work.
I am currently trying out https://stackoverflow.com/questions/4...62035_11377462, but any other suggestions would be great, as about 10 suggestions haven't worked so far. My backspace wouldn't be associated with an editText, but a terminal View. I can't even detect the delete key being pressed.