0

Possible Duplicate:
js: how to find out what character key is pressed?

I want to know how to make an event on key pressing and to specify which key is pressed using Javascript only.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • See this question for your answer. http://stackoverflow.com/questions/1846599/js-how-to-find-out-what-character-key-is-pressed – Brian Hannay Jan 16 '13 at 05:24

1 Answers1

2
<script type="text/javascript">
    function myKeyPress(e){

        var keynum;

        if(window.event){ // IE                 
            keynum = e.keyCode;
        }else
            if(e.which){ // Netscape/Firefox/Opera                  
                keynum = e.which;
             }
        alert(String.fromCharCode(keynum));
    }
   </script>


 <form>
  <input type="text" onkeypress="return myKeyPress(event)" />
 </form>

Referred from How to find out what character key is pressed?

Community
  • 1
  • 1
Engineer
  • 5,911
  • 4
  • 31
  • 58