I'm trying to alert any key-pressed :
alert(String.fromCharCode(e.which));
Seems to work for A-Z a-z characters but not for any other characters.
My goal is to make it work for any character (WYSIWYG).
I'm trying to alert any key-pressed :
alert(String.fromCharCode(e.which));
Seems to work for A-Z a-z characters but not for any other characters.
My goal is to make it work for any character (WYSIWYG).
You can manually provide your own mappings, see my jsfiddle example: https://jsfiddle.net/Glogo/dab3hzz7/1/
sample code:
function myStringFromCharCode(which) {
var strKey = String.fromCharCode(which);
switch(which) {
case 13: return "Shift"
case 17: return "Ctrl"
case 18: return "Alt"
// add more mappings here ...
}
return strKey;
}
function myOnKeyUp(e) {
alert(e.which + "=" + myStringFromCharCode(e.which));
}
document.body.onkeyup=myOnKeyUp;