简体   繁体   中英

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?

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');
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM