简体   繁体   中英

Keypress don't work on some Android devices

I have issue with Android in jQuery Terminal, I've almost fix it, it work on devices I've tested. Demo . But it seems that keypress event don't fire at all (It should echo keypress) on some devices.

On mobile I have code that keep focus on textarea (I resued clipboard) so virtual keyboard is open.

I have this code in keydown:

function keydown_event(e) {
     ...
     if (enabled) {
        ... 
            } else {
                // this get fired while typing
                $.terminal.active().echo('keydown else');
                prevent_keypress = false;
                return;
            }
            // this will prevent for instance backspace to go back one page
            prevent_keypress = true;
            $.terminal.active().echo('keydown return false');
            return false;
        }
     ...
     }
}

and in keypress:

    var doc = $(document.documentElement || window);
    doc.bind('keypress.cmd', function(e) {
        var result;
        if (e.ctrlKey && e.which === 99) { // CTRL+C
            return;
        }
        // this line never get fired while typing
        $.terminal.active().echo('keypress');
        if (prevent_keypress) {
            $.terminal.active().echo('prevent');
            return;
        }
        if (!reverse_search && $.isFunction(options.keypress)) {
            result = options.keypress(e);
        }
        if (result === undefined || result) {
            ...
            self.insert(String.fromCharCode(e.which));
            ...
        } else {
            return result;
        }
    }).bind('keydown.cmd', keydown_event);

Anybody had same issue and know how to fix it, it's hard for me because it work on my devices.

UPDATE I've create simple test to isolate the problem and it seems that keypress is not fired at all.

I manage to fix (almost) the issue by detecting if keypress was not fired and get value from clipboard (for mobile the content it's always the same as terminal input)

var no_keypress;
doc.bind('keydown.cmd', function(e) {
    no_keypress = true;
    ...
}).bind('keypress.cmd', function(e) {
    no_keypress = false;
    ...
}).bind('keyup.cmd', function() {
    if (no_keypress) {
        // Some Androids don't fire keypress - #39
        self.set(clip.val());
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM