Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to check if the caps lock button is active while typing in form?

Tags:

javascript

I was wondering if it was possible to know if the caps lock button is active while filling a web form ?

Sometimes, when you are asked to enter your password, softwares notice you that's active, and you be careful.

I would have liked to do the same in web forms.

Any ideas ?

like image 731
Boris Guéry Avatar asked Jun 01 '09 13:06

Boris Guéry


1 Answers

The following jQuery snippet detects whether caps lock is enabled upon keypress:

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

Taken from StackOverflow answer: https://stackoverflow.com/a/896515/1113435

like image 149
Zar Avatar answered Sep 21 '22 19:09

Zar