Related Posts Plugin for WordPress, Blogger...

About

Follow Us

Tuesday, 7 April 2015

Introduction
Using Jquery or javascript we can detect whether caps Lock is on or off. In this article I will explain how to detect caps lock on or off in JavaScript. Generally to detect or check caps lock on or off in page load it’s not possible we can analyze key code only on key press using jQueryor JavaScript.

Following javascript Code we will use to detect Caps lock:
<script type="text/javascript">
    function checkcapslockon(e) {
        var charKeyCode = e.keyCode ? e.keyCode : e.which;
        var shiftKey = e.shiftKey ? e.shiftKey : ((charKeyCode == 16) ? true : false);
        if (((charKeyCode >= 65 && charKeyCode <= 90) && !shiftKey) || ((charKeyCode >= 97 && charKeyCode <= 122) && shiftKey)) {
            alert('Caps Loc On');
        }
        else {
            alert('Caps Loc Off');
        }
    }
</script>

Full source code for ample Application:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Check Capsloc on or not in Javascript</title>
<script type="text/javascript">
    function checkcapslockon(e) {
        var charKeyCode = e.keyCode ? e.keyCode : e.which;
        var shiftKey = e.shiftKey ? e.shiftKey : ((charKeyCode == 16) ? true : false);
        if (((charKeyCode >= 65 && charKeyCode <= 90) && !shiftKey) || ((charKeyCode >= 97 && charKeyCode <= 122) && shiftKey)) {
            alert('Caps Loc On');
        }
        else {
            alert('Caps Loc Off');
        }
    }
</script>
</head>
<body>
<form id="form1" runat="server">

<center>

<fieldset style="width:350px">
    <legend><strong>Check CapslocK ON or OFF using Javascript</strong></legend>
<div>
<br />
Enter Text:<input type="text" id="txtname" onkeypress="checkcapslockon(event)"/><br /><br />
</div></fieldset></center>
</form>
</body>

</html>
Categories: , ,

0 comments:

Post a Comment