How to check if the caps lock is on in Javascript?

Harish Kumar · · 8058 Views

To detect if the caps lock is on, use the getModifierState() method for the KeyboardEvent object:

const capslockIsOn = event.getModifierState(modifier);

The getModifierState() method returns true if a modifier is active; else, it returns false. So, event.getModifierState('CapsLock') can be used to detect if the caps lock is on.

The following snippet is example to detect if the caps lock is on.

0

Please login or create new account to add your comment.

0 comments
You may also like: