Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check if capslock is on without waiting for the user to type character using JavaScript?

Gmail shows an icon in Chrome when the user has capslock on and focuses on the password field, how are they able to do that?

There are many related question to this, but no one seem to know how to do it without user input, like:

  • How do you tell if caps lock is on using JavaScript?
like image 524
Kit Sunde Avatar asked May 21 '12 07:05

Kit Sunde


People also ask

How can we check whether the caps lock is switched on or off?

To check or detect whether the caps lock key is turned on or off, we can use the getModifierState() method on the input tag KeyBoardEvent and pass the string CapsLock to get the current state of the CapsLock key in JavaScript.

Why do we press the caps lock key?

Caps Lock ⇪ Caps Lock is a button on a computer keyboard that causes all letters of bicameral scripts to be generated in capital letters. It is a toggle key: each press reverses the previous action. Some keyboards also implement a light, to give visual feedback about whether it is on or off.


1 Answers

Nevermind, this is a native function of the Chrome browser when focusing on password field, clever!

like image 186
Kit Sunde Avatar answered Sep 18 '22 04:09

Kit Sunde