Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useMagicKeys weird behavior with meta key #915

Closed
damienroche opened this issue Nov 10, 2021 · 7 comments
Closed

useMagicKeys weird behavior with meta key #915

damienroche opened this issue Nov 10, 2021 · 7 comments

Comments

@damienroche
Copy link
Contributor

const keys = useMagicKeys()
const ctrlK = keys['Meta+K']

watch(ctrlK, (v) => {
  if (v)
    console.log('Meta+K have been pressed')
})

With this code, I have a console log when I pressed Meta+K but after this first log, if I press only Meta key, console is fired. If I press another key then I press Meta key, I no longer have console.log (expected behavior)

Meta+K => console => Control+K have been pressed
Meta => console => Control+K have been pressed
Meta => console => Control+K have been pressed
Meta => console => Control+K have been pressed
K => void
Meta => void
Meta => console => Control+K have been pressed
@damienroche damienroche changed the title useMagicKeys useMagicKeys weird behavior with meta key Nov 10, 2021
@francoism90
Copy link
Contributor

@damienroche Could you try again with { deep: true } as watch option?

@damienroche
Copy link
Contributor Author

@francoism90 I will try it.
also the bug is reproducible on the documentation here :
https://vueuse.org/core/useMagicKeys/

press a meta key and B key for example,
on release KeyB is still displayed on Keys Pressed section. You have to press the B key twice to hide it.

@shayneo
Copy link

shayneo commented Nov 21, 2021

I also am seeing this

@shayneo
Copy link

shayneo commented Nov 22, 2021

It looks like the order of releasing keys matters

Here is a quick example

const { command, a } = useMagicKeys()

Press and holdcmd+a

  • command is true
  • a is true

Release command then release a

  • command is false
  • a is false

Press and holdcmd+a, then release a then release command

  • command is false
  • a is true

@CapitaineToinon
Copy link

I'm having the same issue with useMagicKeys, useKeyModifier and onKeyStoke too. It seems like the browser just never fires the on key up of a key after it's been combined with Meta?

@m0dch3n
Copy link

m0dch3n commented Feb 16, 2022

I created my own solution now

@antfu
Copy link
Member

antfu commented Apr 3, 2022

#1312

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants