본문 바로가기

Javascript Tip

[javascript] 키보드 키값 알아내기

<HEAD>
<SCRIPT language=javascript>

        <!-- script programmed by Lee seung-hyuk -->
        <!--
        n = (document.layers) ? 1:0
        ie = (document.all) ? 1:0
        function keyDown(e) {
                if (n) { var nKey = e.which; var ieKey = 0 }
                if (ie) { var ieKey = event.keyCode; var nKey = 0 }
                alert("키코드값 (넷스케이프의 경우) : " + nKey + "\n키코드값 (익스플로러의 경우) : " + ieKey)
        }
        document.onkeydown = keyDown
        if (n) document.captureEvents(Event.KEYDOWN)        
        // -->
        </SCRIPT>
</HEAD>