

Im seeing a problem where the code stops executing altogether after I click anywhere on the page and I have to either hard refresh or click a certain. Im writing a tampermonkey script that I want to perform an action when a certain set of keys is pressed (cmd + alt + t). An uppercase 'A' is reported as 65 by all events. For example, a lowercase 'a' will be reported as 65 by keydown and keyup, but as 97 by keypress. keyup: Keyup happens when the key is released. keypress: This event is fired when an alphabetic, numeric, or punctuation key is pressed down. The keydown and keyup events provide a code indicating which key is pressed, while keypress indicates which character was entered. There are three different keyboard events in JavaScript: keydown: Keydown happens when the key is pressed down, and auto repeats if the key is pressed down for long. This may be the empty string if the browser or device doesn't know the keyboard's locale. Document.addEventListener () keyup and keydown dont work after click. The keyup event is fired when a key is released. Returns a string representing a locale string indicating the locale the keyboard is configured for. Returns a string representing the key value of the key represented by the event. Returns a boolean value that is true if the event is fired between after compositionstart and before compositionend. Returns a boolean value that is true if the Ctrl key was active when the key event was generated. If you want to display the correct keystrokes to the user, you can use Keyboard.getLayoutMap().

Warning: This ignores the user's keyboard layout, so that if the user presses the key at the "Y" position in a QWERTY keyboard layout (near the middle of the row above the home row), this will always return "KeyY", even if the user has a QWERTZ keyboard (which would mean the user expects a "Z" and all the other properties would indicate a "Z") or a Dvorak keyboard layout (where the user would expect an "F").

This example uses the addEventListener () method to attach a 'keyup' event to an input element.
The onKeyDown, onKeyPress, and onKeyUp events can be used to detect these events respectively. Note that different browsers may have different implementations of the above events. It will occur even if the key released does not produce a character value.
