I am implementing an idle timeout functionality for my website. I want to reset the idle timeout whenever the user interacts with the page, which I want to implement as "the user clicks anywhere on the page" or "the user types a key".
The following code works:
window.addEventListener('click', resetTimeout);
window.addEventListener('keydown', resetTimeout);
Unfortunately it detects modifier keys (alt, shift, ctrl, meta). I don't want to reset the timeout in these cases. For example, when the user alt+tab's to another window, the alt key resets the timeout.
An alternative to keydown
is keypress
, however, it is marked as deprecated. Is there an alternative for keypress
, specifically for the situation I am describing?