How String.fromCharCode function is used in html input fields with mobile keyboard
P粉896751037
P粉896751037 2023-09-01 09:45:04
0
1
728
<p>I want to capture the keyboard key codes and convert them into characters. I am using String.fromCharCode javascript function but it only works with computer keyboard and not with mobile keyboard. Any help would be greatly appreciated. </p> <pre class="brush:php;toolbar:false;">$(".inputsmeter").keyup(function (e) { let key = e.which; let c = String.fromCharCode(key); alert(c); });</pre></p>
P粉896751037
P粉896751037

reply all(1)
P粉334721359

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 works as expected on my iOS Safari 15. Type a in the input and you will see the warning printed:

ev.data: a
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template