How String.fromCharCode function is used in html input fields with mobile keyboard
P粉896751037
2023-09-01 09:45:04
<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>
This works as expected on my iOS Safari 15. Type
a
in the input and you will see the warning printed: