0

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 !!!

yoozer8
  • 7,361
  • 7
  • 58
  • 93
Manikandan Sethuraju
  • 2,873
  • 10
  • 29
  • 48

4 Answers4

4

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();
        }
    }
}
Elliot Bonneville
  • 51,872
  • 23
  • 96
  • 123
2

You can't do this jquery like javascript will be sandboxed inside the browser.

Johnno Nolan
  • 29,228
  • 19
  • 111
  • 160
0

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');
    }
});
Anna Riekic
  • 728
  • 1
  • 13
  • 30
  • isn't `s.toUpperCase() === s && s.toLowerCase() !== s` redundant? – jbabey May 10 '12 at 13:15
  • @jbabey: `s.toLowerCase() !== s` would be false for any character that doesn't have case...like, say, punctuation. Even if `s.toUpperCase() == s` is true. Course, i'd think it might fail the Turkey Test. – cHao May 10 '12 at 13:22
  • Where did this code come from, BTW? It's effectively identical to another now-deleted answer that was posted earlier... – cHao May 10 '12 at 13:35
0

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 :)

ilyes kooli
  • 11,959
  • 14
  • 50
  • 79