Capture global arrow key up

Hello,

Is there any way to capture the arrow key up gobally, no matter what’s the focus element?

Thanks!

Yes, assign listener to the window.

And what’s the way to do that? :slight_smile:

Here is the documentation given by the MDN.

Thanks, I have seen that I can capture the keydown like this:

window.addEventListener('keydown', function(e) {
    console.log(e.keyCode);
});

Now the problem is: how I can send the keydown to Vue? I want to run a method of a component on the keydown event.

Maybe something like this: https://jsfiddle.net/phanan/f49mfme5/

3 Likes

I wanted to do the same and created a component for it that easily implements this functionality wherever you need it:

npm i vue-keypress

Hope it helps :slight_smile: