How to check CAPS lock status in Javascript ?

Sometimes, it happens that after entering the same lucky password, the sign in mechanism doesn’t allow you to enter into the system. You are tired of trying all your passwords but lo, your caps lock is on and you have not noticed it yet. The question is why didn’t the web page indicate it ? The answer is simple they have not added this intelligence to their sign in page. But you can give your user this functionality.

It’s Simple. Lets see how ?

The simple logic is to scan each key code and to guess status of the CAPS lock key. There are two conditions arise.

1. If SHIFT key is not in action and the key code returns ‘A – Z’.
2. If SHIFT key is in action but the key code returns ‘a – z’.

In both the case we can assume that CAPS lock key is on.

1. So at first fetch the status of both the key pressed & status of SHIFT key.

var charKeyCode = e.keyCode ? e.keyCode : e.which;

// To work with both I.E & Gecko . e.keycode:: I.E & e.which :: Gecko.

var shiftKey = e.shiftKey ? e.shiftKey : ((charKeyCode == 16) ? true : false);

// To work with both I.E & Gecko. e.shiftKey :: I.E & charKeyCode == 16 :: Gecko.

2. Then check the above conditions.

// Check both the conditions as described above

if (((charKeyCode >= 65 && charKeyCode = 97 && charKeyCode = 65 && charKeyCode = 97 && charKeyCode
150 150 Burnignorance | Where Minds Meet And Sparks Fly!