0

I have trouble to differentiate capital and lower case letters if Caps Lock is ON or OFF.

I tried This Example but it's not determine Caps Lock.

For e.g. if i press small a OR capital A with Caps Lock On it returns same output.

Thanks for help !

Jaydeep Mor
  • 1,690
  • 3
  • 21
  • 39

1 Answers1

2

You can use the key property of the event object:

If the CapsLock is on, event.key='A', and if it off event.key='a'

document.body.addEventListener('keypress', function(event) {
  console.log(event.key);
});

You can use keyup or keydown events also, it is the same.

sidanmor
  • 5,079
  • 3
  • 23
  • 31