Is there a KeyUp event when a key extends beyond the page?

Currently, I see which keys are pressed using JavaScript using a library that relies on KeyDown/ events KeyUp. Although this works great when keys are pressed / released inside the page, events do not fire when the key goes out of the page (i.e. when it has no focus).

Thus, you can press a key Enterwhen the page has focus (the event will fire, everything will be fine), but when it releases it, when the page does not have focus, the event does not fire, what are the results of my inability to find out if the key is pressed or not.

Regarding the library used, refer to: http://www.n-son.com/scripts/keyLib/keyLib.js

Is it possible to find out when the key is released, when the page has no focus? Or is there perhaps a common function to check if a key is pressed at a specific time?

+3
source share
3 answers

I would reset all your flags with this key down to falsewhen the window loses focus, which you can do using the window blurevent:

var someKeyIsDown;

window.onblur = function() {
    someKeyIsDown = false;
};
+3
source

If they do not interact with "your" program (in the case of a web page, "your" program is part of their web browser), then everything they do will not generate events that your program knows about.

- , (, - ), .

+2

You cannot use higher-level events, such as KeyPressed, that guarantee that a key is pressed and then released?

+1
source

Source: https://habr.com/ru/post/1789243/


All Articles