yan
yan

Reputation: 31

How can i check Caps Lock state in C# (asp.net), client side

How can i check 'Caps Lock' state in C# (asp.net), client side? I can't know what user types because they type id/pw on PKI activeX. So I have to know when they click the PKI call button. (.net framework version 2.0)

When I develop this code ... ▷▶

in aspx (short code)

<head>
    <script type="text/javascript">
        function PKIInstallCheck() {
            if (document.getElementById('capsLock').value == "true"){
                alert ("Caps Lock On");
            }
            // call PKI ActiveX...
        }
    </script>
</head> 
<body>
    <form>
        <asp:ImageButton OnClientClick="return PKIInstallCheck()" runat="server"/>
        <input type="hidden" id="capsLock" name="capsLock" runat="server"/>
    </form>
</body>

in cs (short code)

using System;
using System.windows.forms;
...

public partial class @@@@ : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(Control.IsKeyLocked(Keys.CapsLock))
            capsLock.Value = "true";
        else
            capsLock.Value = "False";
    }
}

But this code just alert CapsLock state on server side. I want to know client's CapsLock state. How can i?

Upvotes: 1

Views: 1547

Answers (1)

AshKher
AshKher

Reputation: 41

why dont you try it using Jquery:

1. call function on keypress 2. get character 3. check if its cap and throw alert.

$('#yourId').keypress(function(e) { 
    var s = String.fromCharCode( e.which );
    if ( s.toUpperCase() === s && s.toLowerCase() !== s && !e.shiftKey ) {
        alert('caps on');
    }
});

Upvotes: 1

Related Questions