From 9ce177d037d0aec26d51cfcba5a091155aebbfc6 Mon Sep 17 00:00:00 2001 From: Minteck Date: Sun, 27 Mar 2022 21:23:27 +0200 Subject: Initial commit --- shortcuts.js | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 shortcuts.js (limited to 'shortcuts.js') diff --git a/shortcuts.js b/shortcuts.js new file mode 100644 index 0000000..027bd3d --- /dev/null +++ b/shortcuts.js @@ -0,0 +1,63 @@ +let keyPressShortcut = false; +global.KeyboardShortcuts = {} + +function KeyboardShortcutHandler(shortcut) { + if (Object.keys(KeyboardShortcuts).includes(shortcut) && document.getElementById("debugging-options").classList.contains("hidden")) { + KeyboardShortcuts[shortcut](); + } else if (!document.getElementById("debugging-options").classList.contains("hidden")) { + DebugMenu.processKey(shortcut); + } +} + +document.onkeyup = KeyboardEventHandler = (e) => { + processKey = true; + if (e.key === "Ctrl" || e.key === "Alt" || e.key === "Shift" || e.key === "Meta") { + if (keyPressShortcut) { + processKey = false; + keyPressShortcut = (e.ctrlKey && !e.altKey && !e.shiftKey && !e.metaKey) || (!e.ctrlKey && e.altKey && !e.shiftKey && !e.metaKey) || (!e.ctrlKey && !e.altKey && e.shiftKey && !e.metaKey) || (!e.ctrlKey && !e.altKey && !e.shiftKey && e.metaKey); + } + } else { + keyPressShortcut = e.ctrlKey || e.altKey || e.shiftKey || e.metaKey; + } + if (processKey) { + shortcut = (e.ctrlKey ? "Control+" : "") + (e.altKey ? "Alt+" : "") + (e.shiftKey ? "Shift+" : "") + (e.metaKey ? "Meta+" : "") + e.key; + console.log(shortcut); + KeyboardShortcutHandler(shortcut); + } +} + +KeyboardShortcuts["Alt+Tab"] = () => { + WindowManager.cycleForward(); +} + +KeyboardShortcuts["Alt+Shift+Tab"] = () => { + WindowManager.cycleBackward(); +} + +KeyboardShortcuts["Meta+ArrowUp"] = KeyboardShortcuts["Alt+Shift+ArrowUp"] = () => { + if (!WindowManager.stack[0].classList.contains("minimized")) WindowManager.maximize(WindowManager.stack[0]); + if (WindowManager.stack[0].classList.contains("minimized")) WindowManager.unminimize(WindowManager.stack[0]); +} + +KeyboardShortcuts["Meta+ArrowDown"] = KeyboardShortcuts["Alt+Shift+ArrowDown"] = () => { + if (!WindowManager.stack[0].classList.contains("maximized")) WindowManager.minimize(WindowManager.stack[0]); + if (WindowManager.stack[0].classList.contains("maximized")) WindowManager.restore(WindowManager.stack[0]); +} + +KeyboardShortcuts["Meta+Q"] = KeyboardShortcuts["Alt+Shift+Q"] = KeyboardShortcuts["Alt+Shift+Ω"] = () => { + WindowManager.close(WindowManager.stack[0]); +} + +KeyboardShortcuts["Meta+ArrowLeft"] = KeyboardShortcuts["Alt+Shift+ArrowLeft"] = () => { + if (WindowManager.stack[0].classList.contains("maximized")) WindowManager.restore(WindowManager.stack[0]); + if (!WindowManager.stack[0].classList.contains("minimized")) WindowManager.paneLeft(WindowManager.stack[0]); +} + +KeyboardShortcuts["Meta+ArrowRight"] = KeyboardShortcuts["Alt+Shift+ArrowRight"] = () => { + if (WindowManager.stack[0].classList.contains("maximized")) WindowManager.restore(WindowManager.stack[0]); + if (!WindowManager.stack[0].classList.contains("minimized")) WindowManager.paneRight(WindowManager.stack[0]); +} + +KeyboardShortcuts["Control+Alt+Delete"] = KeyboardShortcuts["Control+Alt+Backspace"] = () => { + DebugMenu.show(); +} \ No newline at end of file -- cgit