Search...

Thursday, February 16, 2012

Disable any key of keyboard using jQuery


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Disable any key of keyboard
 Page</title>
    <script src="jquery-1.3.2.min.js" type="text/javascript"></script>
    <!--Free downloads on www.jquery.com-->
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <h1>Disable any key of keyboard.</h1>
    </div>
    </form>
</body>
</html>
<script type="text/javascript" language="javascript">
$(document).ready(function() {

     $(this).keydown( function (e) {
        var keycode = null;
        if(window.event) {
            keycode = e.keyCode;
        }else if(e) {
            keycode = e.which;
        }
     
        alert(keycode);
     
       if(keycode=="17"){
       alert("Action prohibited.");//disable Ctrl key
        return false;
       }
       else if(keycode=="8"){
       alert("Action prohibited.");//disable back key
       }
     
    });
});

</script>

********************************************************************************


using System;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}


No comments: