Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert keycode to character using javascript [duplicate]

How to convert keycode to character using javascript

var key_code = 65; 

result should be

character = "a"; 
like image 768
faressoft Avatar asked Oct 20 '10 12:10

faressoft


People also ask

What is e keyCode === 13?

key 13 keycode is for ENTER key.

What is charCode and keyCode?

e.keyCode - used to get the number that represents the key on the keyboard. e.charCode - a number that represents the unicode character of the key on keyboard.

What is the keyCode for enter in JavaScript?

Tests of onkeydown reveal that when the "normal" enter key is pressed, keyCode=13 and location=0; when the numpad enter is pressed, keyCode=13 and location=3.


2 Answers

String.fromCharCode() is what you want:

The fromCharCode() method converts Unicode values to characters.

Syntax

String.fromCharCode(n1, n2, ..., nX) 
like image 168
Skilldrick Avatar answered Oct 27 '22 00:10

Skilldrick


As seen here:

String.fromCharCode((96 <= key && key <= 105) ? key-48 : key) 
like image 28
garsax Avatar answered Oct 26 '22 23:10

garsax