2

I have been looking through the answers to this Stack Overflow question, and it is pretty much just a ton of answers showing different ways to check if CapsLock is on, with some event listener.

In those many solutions, I found one that I think is the best of them all, but there is one problem with all of them. They all depend on some sort of input (onkeyup or click listeners are used), I would like to (if possible) do a check the instant the page is loaded to check if CapsLock is currently on, and then use the solution I chose, to check if the CapsLock state changes during input.

Is this possible?
Is there some way that we can just use the event.getModifierState without having an event?

Jacob Hornbeck
  • 398
  • 2
  • 19
  • Why don't you want to use an event? That's what they're for. – Andy Jun 26 '22 at 02:24
  • 1
    @Christopher - are you sure? – Bravo Jun 26 '22 at 02:37
  • @ggorlen that relies on keypresses occuring – Bravo Jun 26 '22 at 02:41
  • 1
    @Christopher - *it should* - why should it? there's no reason why an artificially created keypress event should detect the state of the hardware – Bravo Jun 26 '22 at 02:42
  • It's not that I don't want to use an event, it's that I want to do it when the page loads. So far the only solutions require a certain type of `eventListener` and uses the event. – Jacob Hornbeck Jun 28 '22 at 03:42
  • I have been wondering the same thing... a static version of the KeyboardEvent.getModifierState function, so you can display the state of the Caps Lock key on page load. – jmdecombe Jul 31 '22 at 07:17
  • I have not found anything. And have not heard anything more about this... As of right now, I do not think it is possible. – Jacob Hornbeck Oct 17 '22 at 11:07

0 Answers0