JavaScript Reference/Javascript Properties/keyCode

Материал из Web эксперт
Версия от 18:30, 25 мая 2010; (обсуждение)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

"keyCode" Example

    
<html>
<body>
<script language="JavaScript">
    function function1() {
        x = event.keyCode; alert("Unicode Value: "+x);
    }
    function function2() {
        x = event.keyCode; alert("Keyboard Value: "+x);
    }
</script>
<p>Press Any Key While The Browser is in Focus</p>
<body onKeyDown="function2();" onKeyPress="function1();">
</body>
</html>



"keyCode" is applied to

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



"keyCode" Syntax and Note

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