fix: "Alt" keybinds getting stuck when switching windows with alt+tab

This commit is contained in:
Pax1601 2025-03-18 13:02:12 +01:00
parent cf86c4ade9
commit 50f3882b3e

View File

@ -21,7 +21,7 @@ export class Shortcut {
ModalEvent.on((modal) => (this.#modal = modal));
/* On keyup, it is enough to check the code only, not the entire combination */
document.addEventListener("keyup", (ev: any) => {
window.addEventListener("keyup", (ev: any) => {
if (this.#modal) return;
if (this.#keydown && this.getOptions().code === ev.code) {
console.log(`Keyup for shortcut ${this.#id}`);
@ -32,7 +32,7 @@ export class Shortcut {
});
/* Forced keyup, in case the window loses focus */
document.addEventListener("blur", (ev: any) => {
window.addEventListener("blur", (ev: any) => {
if (this.#keydown) {
console.log(`Keyup (forced by blur) for shortcut ${this.#id}`);
ev.preventDefault();
@ -42,7 +42,7 @@ export class Shortcut {
});
/* On keydown, check exactly if the requested key combination is being pressed */
document.addEventListener("keydown", (ev: any) => {
window.addEventListener("keydown", (ev: any) => {
if (this.#modal) return;
if (
!(this.#keydown || keyEventWasInInput(ev) || this.getOptions().code !== ev.code) &&