-3

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?

Ario
  • 336
  • 2
  • 3
  • 11

1 Answers1

-2

use String.fromCharCode():

 String.fromCharCode(window.event.keyCode);

Demo

Fix for firefox:

$("#txtInput").keypress(
        function (e) {
             evt = e || window.event;
             var keyPressed = evt.which || evt.keyCode
             console.log(String.fromCharCode(keyPressed));
    });

Demo

Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125