Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save notMasterpiece/0eed4510b41cdb51875cb950afbecc40 to your computer and use it in GitHub Desktop.
Save notMasterpiece/0eed4510b41cdb51875cb950afbecc40 to your computer and use it in GitHub Desktop.
getChar
// event.type должен быть keypress
function getChar(event) {
if (event.which == null) { // IE
if (event.keyCode < 32) return null; // спец. символ
return String.fromCharCode(event.keyCode)
}
if (event.which != 0 && event.charCode != 0) { // все кроме IE
if (event.which < 32) return null; // спец. символ
return String.fromCharCode(event.which); // остальные
}
return null; // спец. символ
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment