Skip to content Skip to sidebar Skip to footer

Keyboard Long Key Press In Android Webview

Anyone have any ideas how to handle a long press of a keyboard key in Android WebView. I had assumed I would simply be able to use the KeyboardEvent repeat property (https://develo

Solution 1:

You could override the document.onkeydown function, then process the corresponding key value through the anti jitter mechanism. After all, what we need to deal with is the key value, not the long key. The code as follows:

var throttle = function(func, delay) {
            var prev = Date.now();
            return function() {
                var context = this;
                var args = arguments;
                var now = Date.now();
                if (now - prev >= delay) {
                    func.apply(context, args);
                    prev = Date.now();
                }
            }
        }
function onkeypress(evt) {
    var keycode = evt.which ? evt.which : evt.keyCode;
    console.log(keycode);
}

document.onkeypress = throttle(onkeypress, 500);

Post a Comment for "Keyboard Long Key Press In Android Webview"