question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onKeyDown code not working on android mobile browsers

See original GitHub issue

Below code is not working properly on mobile browsers, the reason is event.keyCode or event.which is not returning proper value on mobile browser

 onKeyDown: function (event) {
	        var owner = this, pps = owner.properties,
	            charCode = event.which || event.keyCode;

	        // hit backspace when last character is delimiter
	        if (charCode === 8 && Cleave.Util.isDelimiter(owner.element.value.slice(-1), pps.delimiter, pps.delimiters)) {
	            pps.backspace = true;

	            return;
	        }

	        pps.backspace = false;
	    },

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

9reactions
andrglocommented, Jan 19, 2017

It worked using this hack:

    var owner = this,
      pps = owner.properties,
      charCode = event.which || event.keyCode;

    // hit backspace when last character is delimiter

    if (Util.isAndroid() &&
        event.target.value.length &&
        event.target.value.length === this._lastEventValue.length - 1 &&
        Util.isDelimiter(pps.result.slice(-1), pps.delimiter, pps.delimiters)
    ) {
      charCode = 8;
    }
    if (charCode === 8 &&
        Util.isDelimiter(pps.result.slice(-1), pps.delimiter, pps.delimiters)) {
      pps.backspace = true;
    } else {
      pps.backspace = false;
    }
    this._lastEventValue = event.target.value;
8reactions
mony224461commented, Oct 10, 2017

Can anyone help how to write this code…

function isNumberKey(evt){ var charCode = (evt.which) ? evt.which : event.keyCode if ((charCode < 48 || charCode > 57)) return false; return true; };

Read more comments on GitHub >

github_iconTop Results From Across the Web

Keycode is always zero in Chrome for Android - Stack Overflow
I'm running Chrome 27.0.1453.90 on Android 4.1.2 Jelly Bean. The problem can be duplicated with something as simple as: alert(event.keyCode);.
Read more >
my code not working on chrome mobile but all browser working
There certainly some issue with 'keypress' event on Android browser (i.e. chrome mobile). Try replacing it with 'keydown' event, ...
Read more >
keydown and keyup events do not have proper keyCode (it's ...
These problems still seem to be plaguing browsers on Android devices. Keypress events are not firing at all, and keydown/up events are returning...
Read more >
Hostlistener keydown or keypress not working on mobile ...
Hi people,. Im currently working on an angular application where we are trying to prevent people to put invalid characters into a text...
Read more >
Issue 118639 in chromium: keydown and keyup events do not ...
http://code.google.com/p/chromium/issues/detail?id=118639 ... For android browser app, it sends the key code if I type a key, but it
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found