Keydown Event




Type anything in below textbox to trigger, keydown event




Sourcode

    Try It Yourself
 
<html>
<head>


<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />


<script type="text/javascript" language="Javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

</head>
<body>


<h2>Keydown Event</h2>
<hr />
<br /><br />

<b>Type anything in below textbox to trigger, keydown event</b><br />
<input id="txtInput" type="text" />

<br /><br />

<script language="javascript" type="text/javascript">
    $(document).ready(function () {

        $("#txtInput").keydown(
            function (event) {

                if (event.keyCode == 13) {
                    alert("You have pressed enter");
                }
                else if (event.keyCode == 18) {
                    alert("You have pressed Alt key");
                }
                else if (event.keyCode == 32) {
                    alert("You have pressed Spacebar key");
                }
                else if (event.keyCode == 27) {
                    alert("You have pressed Escape key");
                }
                else if (event.keyCode >= 48 && event.keyCode <= 57) {
                    alert("You have pressed numeric key");
                }
                else if ((event.keyCode >= 65 && event.keyCode <= 90) || (event.keyCode >= 97 && event.keyCode <= 122)) {
                    alert("You have pressed alphabet key");
                }                
                else {
                    alert("You have pressed: " + event.keyCode);
                }

            }
        );

    });
</script>


</body>
</html>
Share with your friends!!