简体   繁体   中英

How do i Turn ON/OFF the Caps lock key

We can able to detect the Caps lock key is ON/OFF using Jquery. My question is

"can we possible to Turn ON/OFF the Caps lock key using Jquery or Javascript in Keypress event".

And also using C#, How to achieve this?

Thanks in advance !!!

You can't change whether the caps lock key is on or off. You can however change whether your input strings are lower or upper case with Javascript based on whether the caps lock key is on or off.

for (char in inputString) {
    if(capslock) { // do your caps lock detection here
        if(char === char.toUpperCase()) { // it's upper case
            char = char.toLowerCase();
        } else {
            char = char.toUpperCase();
        }
    }
}

您无法执行此jQuery,因为javascript会在浏览器内部沙箱化。

Detection only:

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

If this would be possible, then I would be able to control user's sound volume, or maybe check what he have in hard disk, I may be more curious and spy his network card traffic...
I would own the world with a simple JavaScript file :)

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