i've a script which captures keyCode(eg: 67, 78..) on keyup
how to get the character of that keyCode (including shift/capslock function)
Like 89 for 'y'
is there are any way using jquery/javascript?
Asked
Active
Viewed 213 times
-3

Ario
- 336
- 2
- 3
- 11
-
1@TarunPai That comment doesn't help OP. You could have flagged the question with a duplicate question link if available or a link which would help OP. – Vamsi Krishna Apr 08 '14 at 06:54
-
Not an answer, and I don't have time to post one, but [this page on keycodes and keyboard events](http://unixpapa.com/js/key.html) may be useful. – T.J. Crowder Apr 08 '14 at 06:54
-
if u dont have the solution please don vote or comment @Tarun – Ario Apr 08 '14 at 06:56
-
1There are rules here on SO on the kind of questions you should as and should NOT ask, read up here - http://stackoverflow.com/help/dont-ask – painotpi Apr 08 '14 at 07:02
-
I presume you mean `'y'` -> `121`, not `89`? – Qantas 94 Heavy Apr 08 '14 at 07:43
1 Answers
-2
String.fromCharCode(window.event.keyCode);
Fix for firefox:
$("#txtInput").keypress(
function (e) {
evt = e || window.event;
var keyPressed = evt.which || evt.keyCode
console.log(String.fromCharCode(keyPressed));
});

Milind Anantwar
- 81,290
- 25
- 94
- 125
-
4Keycodes aren't what `fromCharCode` uses. Keycodes are...[keycodes](http://unixpapa.com/js/key.html). `fromCharCode` accepts Unicode code points (well, the first 65,536 of them; I hear ES6 will expand that). – T.J. Crowder Apr 08 '14 at 06:51
-
1ITS WORKING BUT ITS ONLY GIVING UPPERCASE CHARS AND not correctly giving non english characters (eg: '.],)... any fix? – Ario Apr 08 '14 at 06:53
-
1Using `window.event.keyCode` doesn't change anything, and breaks Firefox. – Qantas 94 Heavy Apr 08 '14 at 06:57
-
-
1This answer is still incorrect. Paste this code into the console: `document.onkeyup = function () { console.log(String.fromCharCode(window.event.keyCode)); };`, then press the `\`` key on your keyboard. Is that the same character? This also throws a TypeError in Firefox. – Qantas 94 Heavy Apr 08 '14 at 07:16
-
-
@onekitten ` is the same character... and Millind's demo is working perfectly in all browsers... including IE – Ario Apr 08 '14 at 08:07
-