3

I am facing a problem. I have to identify my Caps Lock is on or not?

If my caps lock on then i have to tell user that your caps on. but the problem is if some one press shift + A then it should behave normally.i think key events of Caps Lock on + a equal to Shift + a.

How can i identify only my Caps Lock key on. i have seen some example in stackoevrflow but these are not working fine.

This all should be using javascript or jquery.

qiao
  • 17,941
  • 6
  • 57
  • 46
Pankaj
  • 4,419
  • 16
  • 50
  • 72
  • possible duplicate of [Detect caps lock on/off using jQuery](http://stackoverflow.com/questions/2308895/detect-caps-lock-on-off-using-jquery) – Matt Jan 17 '12 at 14:03
  • Like you said, I don't know if you can detect it. Most programs seem to just go with a generic warning of "make sure your caps lock is off" and that it's case sensitive. Of course, you could detect several capitals in a row and then "suspect" that caps lock is on... – karnok Jan 17 '12 at 14:04
  • you have to check for the shift on every key up. – Joseph Le Brech Jan 17 '12 at 14:06
  • @Matt- in javascript/jquery Caps Lock on + a and Shift + a returning same sky code. so i can not differentiate them using current code provided in current answer. – Pankaj Jan 17 '12 at 14:06

2 Answers2

1
<input type="text" onkeypress="handleKeyPress(event)" />

function handleKeyPress(e){

    var key = e.keyCode ? e.keyCode : e.charCode;
    if(key >= 65 && key <=90 && !e.shiftKey){

        alert("CAPS LOCK ON");

    }

}

jsfiddle : http://jsfiddle.net/diode/pNc35/2/

Diode
  • 24,570
  • 8
  • 40
  • 51
0

try the following

http://dougalmatthews.com/articles/2008/jul/2/javascript-detecting-caps-lock/

Joseph Le Brech
  • 6,541
  • 11
  • 49
  • 84
  • sorry friend, this code is not working for me.when your caps lock on it will return e.shiftKey= true, it fails for me – Pankaj Jan 17 '12 at 14:24
  • have a look at the article this question is a duplicate of http://stackoverflow.com/questions/2308895/detect-caps-lock-on-off-using-jquery there's a second solution in there. also this problem has no definite solution as browsers suck. (so it may never work correctly in some browsers) – Joseph Le Brech Jan 17 '12 at 15:07