I have a problem with handling jQuery Terminal library on Android. Since like forever Android don’t trigger keypress or keydown event, and you need to generate it from input event.
And in the library I used this code to detect if user press ENTER:
function input_event() {
debug('input ' + no_keydown + ' || ' + process + ' ((' + no_keypress +
' || ' + dead_key + ') && !' + skip_insert + ' && (' + single_key +
' || ' + no_key + ') && !' + backspace + ')');
// correct for fake space used for select all context menu hack
var val = clip.val();
debug('command => ' + val + ' :: ' + command);
if (!is_mobile) {
val = val.replace(/^ /, '');
}
// Some Androids don't fire keypress - #39
// if there is dead_key we also need to grab real character #158
// Firefox/Android with google keyboard don't fire keydown and keyup #319
if (no_keydown || process || ((no_keypress || dead_key) &&
!skip_insert &&
(single_key || no_key) && !backspace)) {
if (val && val === command) {
if (is_android) {
// ignore autocomplete on GBoard keyboard #693
if (no_keydown) {
event('keydown', 'Enter', 13);
}
}
finalize_input_event();
return;
}
Editable element is called clip
because I also use it for clipboard handling.
The problem is that this doesn’t work with dot after text. When you press dot, it triggers an input event for old text, which triggers ENTER. (I’m not sure if this always how it was working).
So the question is how to properly detect ENTER key when all you have is an Input event?
I use contenteditabe
element, so I can’t use form submit.
This is my testing page: https://terminal.jcubic.pl/andorid.php (the contenteditable is visible to help debugging).