on-internet
← Community

How to detect Caps Lock state on page load (that is, not on keypress) with JavaScript?

Stack Overflow ·

So I've been researching solutions for Caps Lock detection for a form, using JavaScript/jQuery. There is a huge thread on stackoverflow offering many solutions. But the only problem is they don't check whether Caps Lock is pressed directly per se. They detect whether a capital letter has been entered and that the shift key has not been depressed. The drawbacks of this is that my Caps Lock warning message will not toggle on/off until the user starts typing into the form, which is hardly optimal. Here is my code. document.onkeypress = function(e){ e = e || window.event; var s = String.fromCharCo

Comments

Sign in or sign up to comment and upvote.

No comments yet.