JavaScript Reference/Javascript Properties/keyCode

Материал из Web эксперт
Перейти к: навигация, поиск

"keyCode" Example

   <source lang="javascript">
   

<html> <body> <script language="JavaScript">

   function function1() {
       x = event.keyCode; alert("Unicode Value: "+x);
   }
   function function2() {
       x = event.keyCode; alert("Keyboard Value: "+x);
   }

</script>

Press Any Key While The Browser is in Focus

<body onKeyDown="function2();" onKeyPress="function1();"> </body> </html>


     </source>
   
  


"keyCode" is applied to

   <source lang="javascript">

+----------------+--------------------------------------------------------------+ | Applied_To |event | +----------------+--------------------------------------------------------------+

     </source>
   
  


"keyCode" Syntax and Note

   <source lang="javascript">

Note: Read-only property. Returns the key code pressed. Used with the onKeyDown, onKeyUp, and onKeyPress events. onKeyPress event, the return value is in Unicode.

                        This code distinguishes between uppercase and 
                        lowercase characters. 

onKeyDown and the return value code is a character code. onKeyUp events,

Syntax:

window.event.keyCode


     </source>