johnlemon
johnlemon

Reputation: 21449

Convert key code to character

Why are some keycodes converted to other characters?

http://jsfiddle.net/h9268/

I think 219 should be the [ character.

onKeyPress I get 91
onKeyDown I get 219

firefox, test page: http://www.asquare.net/javascript/tests/KeyCode.html

Update: the confusion was generated by the keycode of onKeyPress and onKeyDown event. onKeyPress the character code is returned ( 91 ) and onKeyDown the key code is returned ( 219 ).

This table shows both ascii code and key code ( by browser ). http://unixpapa.com/js/key.html

Upvotes: 2

Views: 679

Answers (3)

Arsen Mkrtchyan
Arsen Mkrtchyan

Reputation: 50712

It converts to Unicode, here is Here is table of conversion, use 91 instead

Upvotes: 1

Snake Eyes
Snake Eyes

Reputation: 16754

W3Schools says:

Definition and Usage

The fromCharCode() method converts Unicode values into characters.

Note: This is a static method of the String object, and the syntax is always String.fromCharCode().

Instead of 219 must be 91 for [ character

219 means for keyCode not charCode

Upvotes: 0

Rhyono
Rhyono

Reputation: 2468

That's for Unicode. It's taking the Unicode values and converting it to Unicode characters.

Upvotes: 2

Related Questions