0

I want to capture the keyboard key code and convert it to characters. I am using the String.fromCharCode javascript function but it only works on a computer keyboard it is not working with a mobile keypad. Any help will be appreciated.

$(".inputsmeter").keyup(function (e) { 
  let key = e.which; 
  let c = String.fromCharCode(key); 
  alert(c); 
});
Omar
  • 32,302
  • 9
  • 69
  • 112
mutahir
  • 97
  • 3
  • 11

1 Answers1

0

const inputElem = document.getElementById('input')
inputElem.addEventListener('input', (ev) => { 
  console.log(ev);
  alert(`e.data: ${ev.data}`);
});
<input id="input" type="text" placeholder="type something... " />

This runs as expected on my iOS Safari 15. Type a in the input will see an alert printing:

ev.data: a
jjj
  • 378
  • 1
  • 6
  • The same problem is on Samsung mobile , the browser chrome it shows different characters in the alert. in a laptop t works okay but not on mobile. – mutahir Nov 22 '22 at 16:31
  • I just want some script for OTP code which runs works for both laptops and mobile and the keys like backspace and when entering a character jumps to following input also replace of existing input work when clicking on already filled information in puts. – mutahir Nov 23 '22 at 05:38
  • Replaced `keyup` with `input` which should work on Android – jjj Nov 25 '22 at 21:18