How to determine when the status of the Alt key changes

I have a user interface that provides some functions that recognize if the alt key is turned off to define some alternative functions when pressed and interacting with the user interface. However, since there is usually no alt key on a mobile device, there is also a graphic area on the screen that can be used as a button to switch alternative functions. The appearance of the element is changed to indicate whether alternative functionality is enabled. For consistency, this element also changes appearance when the alt button is not available, and the state of this element is what it is connected with to determine whether alternative functions should be called.

The problem is that in some cases there is no notification that the alt key is released, and thus the visual representation is incorrect. For example, when the user alt + fits into the window, there are no key events indicating that the alt key has been released. To get around this, the window's onblur event is used to designate the alt key as released, since the user cannot return alt + tab without releasing the alt key, and if the Alt key is held pressed to bring the window to focus by other means, the event onkeydownfires several times.

However, there are other ways to use the alt key that I cannot figure out how to determine the release. For example, in Chrome, if I hit alt + space, and then click on the window to close the menu window, there are no key events, even if I can check the altKey flag and find it false. The same is true for alt + f and even alt + shift + i until the alt key is released before the dialog box appears. Worse, none of them even triggers any blurry events in a window, document or document. Unless I clearly have more attention. I can in some cases use something like onclickor as @trincot notes onmousemoveto detect alt issued in some cases, but not for all.

- , alt , , , alt .

Alt?

+4

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


All Articles