question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

useKeyModifier: CapsLock does not get set back to false directly

See original GitHub issue

I use const capsLockState = useKeyModifier('CapsLock') to detect if the caps lock is currently active or not.

On first press it activates correctly, but on second press (turning it off again) it doesn’t get set to false directly. After a click on the website or pressing any key after disabling, it turns to false.

I can reproduce this in the Demo: https://vueuse.org/core/useKeyModifier

Using an Ubuntu 20.04 with Chrome 97.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
JMaylorcommented, Jan 24, 2022

Hey @Shinigami92. I wrote this useKeyModifier function and just want to let you know the reason behind ‘bug 1’ - why the state is updated on ANY key press. If you imagine the following situation in the case that we only updated on the modifier key being pressed:

  1. User turns CAPS on while on your website. Modifier state is updated to true.
  2. User tabs off your site and turns CAPS off. Your page can’t detect this keypress and so doesn’t update the modifier state to false.
  3. User comes back to your site and continues typing. There is no CAPS press so they are now typing with CAPS off, but your app thinks CAPS is on.

Hope that makes sense. No matter what key you press, the event exposes the current modifier state of all modifier keys via the getModifierState function.

You can add more listeners to update the state more regularly, at the cost of performance. e.g. mousemove events also provide modifier states - see https://github.com/vueuse/vueuse/pull/698#issuecomment-908241915

In terms of picking up the initial modifier state on page load, I looked into this at the time and couldn’t find a way to do it. If you simulate a key press through JS, all the modifier states are false. They are only populated on a ‘real’ keyboard event - SO thread

1reaction
wheatjscommented, Jan 19, 2022

Strange, I’m unable to reproduce on my end

Read more comments on GitHub >

github_iconTop Results From Across the Web

useKeyModifier - VueUse
Reactive Modifier State. Tracks state of any of the supported modifiers - see Browser Compatibility notes. Demo #. source. capsLock. numLock. scrollLock.
Read more >
How do you tell if caps lock is on using JavaScript?
You can detect caps lock using "is letter uppercase and no shift pressed" using a keypress capture on the document ...
Read more >
CAPS LOCK woes · Issue #2350 · Hammerspoon ... - GitHub
Is there any way, using only Hammerspoon, to set up CAPS LOCK to act ... if hs.hid.capslock.get() then hs.hid.capslock.set(false) hs.alert.
Read more >
How to fix Caps Lock indicator not working on Windows 10/11?
Make sure you know the exact details of your device and is aware what you should look for, since downloading and installing a...
Read more >
Caps lock always turn on after switching from Wind...
I have a really annoying problem since I upgraded to vmware fusion 10 ... in my original keyboard, the Caps Lock Key was...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found