diff --git a/src/Bladeburner/ui/Console.tsx b/src/Bladeburner/ui/Console.tsx index c64957714..f4144d24f 100644 --- a/src/Bladeburner/ui/Console.tsx +++ b/src/Bladeburner/ui/Console.tsx @@ -1,5 +1,6 @@ import React, { useState, useRef, useEffect } from "react"; import { IBladeburner } from "../IBladeburner"; +import { KEY } from "../../utils/helpers/keyCodes"; import { IPlayer } from "../../PersonObjects/IPlayer"; import Paper from "@mui/material/Paper"; @@ -76,7 +77,7 @@ export function Console(props: IProps): React.ReactElement { }, []); function handleKeyDown(event: React.KeyboardEvent): void { - if (event.keyCode === 13) { + if (event.key === KEY.ENTER) { event.preventDefault(); if (command.length > 0) { props.bladeburner.postToConsole("> " + command); @@ -88,7 +89,7 @@ export function Console(props: IProps): React.ReactElement { const consoleHistory = props.bladeburner.consoleHistory; - if (event.keyCode === 38) { + if (event.key === KEY.S) { // up let i = consoleHistoryIndex; const len = consoleHistory.length; @@ -108,7 +109,7 @@ export function Console(props: IProps): React.ReactElement { setCommand(prevCommand); } - if (event.keyCode === 40) { + if (event.key === KEY.DOWNARROW) { const i = consoleHistoryIndex; const len = consoleHistory.length; diff --git a/src/Corporation/ui/BuybackSharesModal.tsx b/src/Corporation/ui/BuybackSharesModal.tsx index 4d6568af7..250443817 100644 --- a/src/Corporation/ui/BuybackSharesModal.tsx +++ b/src/Corporation/ui/BuybackSharesModal.tsx @@ -8,6 +8,7 @@ import Button from "@mui/material/Button"; import TextField from "@mui/material/TextField"; import { BuyBackShares } from '../Actions'; import { dialogBoxCreate } from '../../ui/React/DialogBox'; +import { KEY } from "../../utils/helpers/keyCodes"; interface IProps { open: boolean; @@ -69,7 +70,7 @@ export function BuybackSharesModal(props: IProps): React.ReactElement { } function onKeyDown(event: React.KeyboardEvent): void { - if (event.keyCode === 13) buy(); + if (event.key === KEY.ENTER) buy(); } return ( diff --git a/src/Corporation/ui/ExpandIndustryTab.tsx b/src/Corporation/ui/ExpandIndustryTab.tsx index 8477a8a76..74faabadf 100644 --- a/src/Corporation/ui/ExpandIndustryTab.tsx +++ b/src/Corporation/ui/ExpandIndustryTab.tsx @@ -11,6 +11,7 @@ import TextField from "@mui/material/TextField"; import MenuItem from "@mui/material/MenuItem"; import Box from "@mui/material/Box"; import Select, { SelectChangeEvent } from "@mui/material/Select"; +import { KEY } from "../../utils/helpers/keyCodes"; interface IProps { setDivisionName: (name: string) => void; @@ -53,7 +54,7 @@ export function ExpandIndustryTab(props: IProps): React.ReactElement { } function onKeyDown(event: React.KeyboardEvent): void { - if (event.keyCode === 13) newIndustry(); + if (event.key === KEY.ENTER) newIndustry(); } function onIndustryChange(event: SelectChangeEvent): void { diff --git a/src/Corporation/ui/GoPublicModal.tsx b/src/Corporation/ui/GoPublicModal.tsx index 5d093cf8c..6c91e1513 100644 --- a/src/Corporation/ui/GoPublicModal.tsx +++ b/src/Corporation/ui/GoPublicModal.tsx @@ -7,6 +7,7 @@ import Typography from "@mui/material/Typography"; import Button from "@mui/material/Button"; import TextField from "@mui/material/TextField"; import Box from "@mui/material/Box"; +import { KEY } from "../../utils/helpers/keyCodes"; interface IProps { open: boolean; @@ -45,7 +46,7 @@ export function GoPublicModal(props: IProps): React.ReactElement { } function onKeyDown(event: React.KeyboardEvent): void { - if (event.keyCode === 13) goPublic(); + if (event.key === KEY.ENTER) goPublic(); } function onChange(event: React.ChangeEvent): void { diff --git a/src/Corporation/ui/IssueDividendsModal.tsx b/src/Corporation/ui/IssueDividendsModal.tsx index 873fd1a1f..351776dca 100644 --- a/src/Corporation/ui/IssueDividendsModal.tsx +++ b/src/Corporation/ui/IssueDividendsModal.tsx @@ -7,6 +7,7 @@ import { useCorporation } from "./Context"; import Typography from "@mui/material/Typography"; import TextField from "@mui/material/TextField"; import Button from "@mui/material/Button"; +import { KEY } from "../../utils/helpers/keyCodes"; interface IProps { open: boolean; onClose: () => void; @@ -32,7 +33,7 @@ export function IssueDividendsModal(props: IProps): React.ReactElement { } function onKeyDown(event: React.KeyboardEvent): void { - if (event.keyCode === 13) issueDividends(); + if (event.key === KEY.ENTER) issueDividends(); } function onChange(event: React.ChangeEvent): void { diff --git a/src/Corporation/ui/IssueNewSharesModal.tsx b/src/Corporation/ui/IssueNewSharesModal.tsx index 63ccb5cb4..0022828e9 100644 --- a/src/Corporation/ui/IssueNewSharesModal.tsx +++ b/src/Corporation/ui/IssueNewSharesModal.tsx @@ -8,6 +8,7 @@ import { useCorporation } from "./Context"; import Typography from "@mui/material/Typography"; import TextField from "@mui/material/TextField"; import Button from "@mui/material/Button"; +import { KEY } from "../../utils/helpers/keyCodes"; interface IEffectTextProps { shares: number | null; @@ -93,7 +94,7 @@ export function IssueNewSharesModal(props: IProps): React.ReactElement { } function onKeyDown(event: React.KeyboardEvent): void { - if (event.keyCode === 13) issueNewShares(); + if (event.key === KEY.ENTER) issueNewShares(); } function onChange(event: React.ChangeEvent): void { diff --git a/src/Corporation/ui/LimitProductProductionModal.tsx b/src/Corporation/ui/LimitProductProductionModal.tsx index 3c5dcd96d..2d28ea75f 100644 --- a/src/Corporation/ui/LimitProductProductionModal.tsx +++ b/src/Corporation/ui/LimitProductProductionModal.tsx @@ -5,6 +5,7 @@ import { Modal } from "../../ui/React/Modal"; import Typography from "@mui/material/Typography"; import Button from "@mui/material/Button"; import TextField from "@mui/material/TextField"; +import { KEY } from "../../utils/helpers/keyCodes"; interface IProps { open: boolean; @@ -25,7 +26,7 @@ export function LimitProductProductionModal(props: IProps): React.ReactElement { } function onKeyDown(event: React.KeyboardEvent): void { - if (event.keyCode === 13) limitProductProduction(); + if (event.key === KEY.ENTER) limitProductProduction(); } function onChange(event: React.ChangeEvent): void { diff --git a/src/Corporation/ui/MakeProductModal.tsx b/src/Corporation/ui/MakeProductModal.tsx index e040bfdfd..784e3acda 100644 --- a/src/Corporation/ui/MakeProductModal.tsx +++ b/src/Corporation/ui/MakeProductModal.tsx @@ -9,6 +9,7 @@ import TextField from "@mui/material/TextField"; import Button from "@mui/material/Button"; import MenuItem from "@mui/material/MenuItem"; import Select, { SelectChangeEvent } from "@mui/material/Select"; +import { KEY } from "../../utils/helpers/keyCodes"; interface IProps { open: boolean; @@ -165,7 +166,7 @@ export function MakeProductModal(props: IProps): React.ReactElement { } function onKeyDown(event: React.KeyboardEvent): void { - if (event.keyCode === 13) makeProduct(); + if (event.key === KEY.ENTER) makeProduct(); } return ( diff --git a/src/Corporation/ui/PurchaseMaterialModal.tsx b/src/Corporation/ui/PurchaseMaterialModal.tsx index 5c6f6bda8..419176e6d 100644 --- a/src/Corporation/ui/PurchaseMaterialModal.tsx +++ b/src/Corporation/ui/PurchaseMaterialModal.tsx @@ -10,6 +10,7 @@ import { useCorporation, useDivision } from "./Context"; import Typography from "@mui/material/Typography"; import TextField from "@mui/material/TextField"; import Button from "@mui/material/Button"; +import { KEY } from "../../utils/helpers/keyCodes"; interface IBulkPurchaseTextProps { warehouse: Warehouse; @@ -68,7 +69,7 @@ function BulkPurchaseSection(props: IBPProps): React.ReactElement { } function onKeyDown(event: React.KeyboardEvent): void { - if (event.keyCode === 13) bulkPurchase(); + if (event.key === KEY.ENTER) bulkPurchase(); } function onChange(event: React.ChangeEvent): void { @@ -123,7 +124,7 @@ export function PurchaseMaterialModal(props: IProps): React.ReactElement { } function onKeyDown(event: React.KeyboardEvent): void { - if (event.keyCode === 13) purchaseMaterial(); + if (event.key === KEY.ENTER) purchaseMaterial(); } function onChange(event: React.ChangeEvent): void { diff --git a/src/Corporation/ui/SellMaterialModal.tsx b/src/Corporation/ui/SellMaterialModal.tsx index 366507aa9..83a36d314 100644 --- a/src/Corporation/ui/SellMaterialModal.tsx +++ b/src/Corporation/ui/SellMaterialModal.tsx @@ -6,6 +6,7 @@ import { Modal } from "../../ui/React/Modal"; import Typography from "@mui/material/Typography"; import TextField from "@mui/material/TextField"; import Button from "@mui/material/Button"; +import { KEY } from "../../utils/helpers/keyCodes"; function initialPrice(mat: Material): string { let val = mat.sCost ? mat.sCost + "" : ""; @@ -46,7 +47,7 @@ export function SellMaterialModal(props: IProps): React.ReactElement { } function onKeyDown(event: React.KeyboardEvent): void { - if (event.keyCode === 13) sellMaterial(); + if (event.key === KEY.ENTER) sellMaterial(); } return ( diff --git a/src/Corporation/ui/SellProductModal.tsx b/src/Corporation/ui/SellProductModal.tsx index 5b383a583..00026a5b0 100644 --- a/src/Corporation/ui/SellProductModal.tsx +++ b/src/Corporation/ui/SellProductModal.tsx @@ -9,6 +9,7 @@ import TextField from "@mui/material/TextField"; import Button from "@mui/material/Button"; import FormControlLabel from "@mui/material/FormControlLabel"; import Switch from "@mui/material/Switch"; +import { KEY } from "../../utils/helpers/keyCodes"; function initialPrice(product: Product): string { let val = product.sCost ? product.sCost + "" : ""; @@ -58,7 +59,7 @@ export function SellProductModal(props: IProps): React.ReactElement { } function onKeyDown(event: React.KeyboardEvent): void { - if (event.keyCode === 13) sellProduct(); + if (event.key === KEY.ENTER) sellProduct(); } return ( diff --git a/src/Corporation/ui/SellSharesModal.tsx b/src/Corporation/ui/SellSharesModal.tsx index e96fa9959..a6a36aa0d 100644 --- a/src/Corporation/ui/SellSharesModal.tsx +++ b/src/Corporation/ui/SellSharesModal.tsx @@ -10,6 +10,7 @@ import TextField from "@mui/material/TextField"; import Button from "@mui/material/Button"; import { Money } from "../../ui/React/Money"; import { SellShares } from "../Actions"; +import { KEY } from "../../utils/helpers/keyCodes"; interface IProps { open: boolean; onClose: () => void; @@ -68,7 +69,7 @@ export function SellSharesModal(props: IProps): React.ReactElement { } function onKeyDown(event: React.KeyboardEvent): void { - if (event.keyCode === 13) sell(); + if (event.key === KEY.ENTER) sell(); } return ( diff --git a/src/Corporation/ui/ThrowPartyModal.tsx b/src/Corporation/ui/ThrowPartyModal.tsx index 8b89c4506..c3e2958cb 100644 --- a/src/Corporation/ui/ThrowPartyModal.tsx +++ b/src/Corporation/ui/ThrowPartyModal.tsx @@ -10,6 +10,7 @@ import Typography from "@mui/material/Typography"; import Button from "@mui/material/Button"; import TextField from "@mui/material/TextField"; import Box from "@mui/material/Box"; +import { KEY } from "../../utils/helpers/keyCodes"; interface IProps { open: boolean; @@ -57,7 +58,7 @@ export function ThrowPartyModal(props: IProps): React.ReactElement { } function onKeyDown(event: React.KeyboardEvent): void { - if (event.keyCode === 13) throwParty(); + if (event.key === KEY.ENTER) throwParty(); } return ( diff --git a/src/Faction/ui/CreateGangModal.tsx b/src/Faction/ui/CreateGangModal.tsx index 5d023376c..60d788494 100644 --- a/src/Faction/ui/CreateGangModal.tsx +++ b/src/Faction/ui/CreateGangModal.tsx @@ -6,6 +6,7 @@ import { Modal } from "../../ui/React/Modal"; import { use } from "../../ui/Context"; import Typography from "@mui/material/Typography"; import Button from "@mui/material/Button"; +import { KEY } from "../../utils/helpers/keyCodes"; import { FactionNames } from "../data/FactionNames"; interface IProps { @@ -38,7 +39,7 @@ export function CreateGangModal(props: IProps): React.ReactElement { } function onKeyUp(event: React.KeyboardEvent): void { - if (event.keyCode === 13) createGang(); + if (event.key === KEY.ENTER) createGang(); } return ( diff --git a/src/Gang/ui/RecruitModal.tsx b/src/Gang/ui/RecruitModal.tsx index c5096ba74..4c81c36fc 100644 --- a/src/Gang/ui/RecruitModal.tsx +++ b/src/Gang/ui/RecruitModal.tsx @@ -8,6 +8,7 @@ import { useGang } from "./Context"; import Typography from "@mui/material/Typography"; import TextField from "@mui/material/TextField"; import Button from "@mui/material/Button"; +import { KEY } from "../../utils/helpers/keyCodes"; interface IRecruitPopupProps { open: boolean; @@ -34,7 +35,7 @@ export function RecruitModal(props: IRecruitPopupProps): React.ReactElement { } function onKeyUp(event: React.KeyboardEvent): void { - if (event.keyCode === 13) recruit(); + if (event.key === KEY.ENTER) recruit(); } function onChange(event: React.ChangeEvent): void { diff --git a/src/Locations/ui/PurchaseServerModal.tsx b/src/Locations/ui/PurchaseServerModal.tsx index d0f8ccf44..ed54a7faa 100644 --- a/src/Locations/ui/PurchaseServerModal.tsx +++ b/src/Locations/ui/PurchaseServerModal.tsx @@ -10,6 +10,7 @@ import { use } from "../../ui/Context"; import Typography from "@mui/material/Typography"; import TextField from "@mui/material/TextField"; import Button from "@mui/material/Button"; +import { KEY } from "../../utils/helpers/keyCodes"; interface IProps { open: boolean; @@ -29,7 +30,7 @@ export function PurchaseServerModal(props: IProps): React.ReactElement { } function onKeyUp(event: React.KeyboardEvent): void { - if (event.keyCode === 13) tryToPurchaseServer(); + if (event.key === KEY.ENTER) tryToPurchaseServer(); } function onChange(event: React.ChangeEvent): void { diff --git a/src/Sidebar/ui/SidebarRoot.tsx b/src/Sidebar/ui/SidebarRoot.tsx index bd1a1fbf8..81f724304 100644 --- a/src/Sidebar/ui/SidebarRoot.tsx +++ b/src/Sidebar/ui/SidebarRoot.tsx @@ -1,4 +1,5 @@ import React, { useState, useEffect } from "react"; +import { KEY } from "../../utils/helpers/keyCodes"; import clsx from "clsx"; import { styled, Theme, CSSObject } from "@mui/material/styles"; import createStyles from "@mui/styles/createStyles"; @@ -53,7 +54,6 @@ import { Settings } from "../../Settings/Settings"; import { redPillFlag } from "../../RedPill"; import { AugmentationNames } from "../../Augmentation/data/AugmentationNames"; -import { KEY } from "../../utils/helpers/keyCodes"; import { ProgramsSeen } from "../../Programs/ui/ProgramsRoot"; import { InvitationsSeen } from "../../Faction/ui/FactionsRoot"; import { hash } from "../../hash/hash"; @@ -276,54 +276,54 @@ export function SidebarRoot(props: IProps): React.ReactElement { function handleShortcuts(this: Document, event: KeyboardEvent): any { if (Settings.DisableHotkeys) return; if ((props.player.isWorking && props.player.focus) || redPillFlag) return; - if (event.keyCode == KEY.T && event.altKey) { + if (event.key === "t" && event.altKey) { event.preventDefault(); clickTerminal(); - } else if (event.keyCode === KEY.C && event.altKey) { + } else if (event.key === KEY.C && event.altKey) { event.preventDefault(); clickStats(); - } else if (event.keyCode === KEY.E && event.altKey) { + } else if (event.key === KEY.E && event.altKey) { event.preventDefault(); clickScriptEditor(); - } else if (event.keyCode === KEY.S && event.altKey) { + } else if (event.key === KEY.S && event.altKey) { event.preventDefault(); clickActiveScripts(); - } else if (event.keyCode === KEY.H && event.altKey) { + } else if (event.key === KEY.H && event.altKey) { event.preventDefault(); clickHacknet(); - } else if (event.keyCode === KEY.W && event.altKey) { + } else if (event.key === KEY.W && event.altKey) { event.preventDefault(); clickCity(); - } else if (event.keyCode === KEY.J && event.altKey && !event.ctrlKey && !event.metaKey && canJob) { + } else if (event.key === KEY.J && event.altKey && !event.ctrlKey && !event.metaKey && canJob) { // ctrl/cmd + alt + j is shortcut to open Chrome dev tools event.preventDefault(); clickJob(); - } else if (event.keyCode === KEY.R && event.altKey) { + } else if (event.key === KEY.R && event.altKey) { event.preventDefault(); clickTravel(); - } else if (event.keyCode === KEY.P && event.altKey) { + } else if (event.key === KEY.P && event.altKey) { event.preventDefault(); clickCreateProgram(); - } else if (event.keyCode === KEY.F && event.altKey) { + } else if (event.key === KEY.F && event.altKey) { if (props.page == Page.Terminal && Settings.EnableBashHotkeys) { return; } event.preventDefault(); clickFactions(); - } else if (event.keyCode === KEY.A && event.altKey) { + } else if (event.key === KEY.A && event.altKey) { event.preventDefault(); clickAugmentations(); - } else if (event.keyCode === KEY.U && event.altKey) { + } else if (event.key === KEY.U && event.altKey) { event.preventDefault(); clickTutorial(); - } else if (event.keyCode === KEY.B && event.altKey && props.player.bladeburner) { + } else if (event.key === KEY.B && event.altKey && props.player.bladeburner) { event.preventDefault(); clickBladeburner(); - } else if (event.keyCode === KEY.G && event.altKey && props.player.gang) { + } else if (event.key === KEY.G && event.altKey && props.player.gang) { event.preventDefault(); clickGang(); } - // if (event.keyCode === KEY.O && event.altKey) { + // if (event.key === KEY.O && event.altKey) { // event.preventDefault(); // gameOptionsBoxOpen(); // } diff --git a/src/Terminal/ui/TerminalInput.tsx b/src/Terminal/ui/TerminalInput.tsx index 318a77765..a45d7ec6b 100644 --- a/src/Terminal/ui/TerminalInput.tsx +++ b/src/Terminal/ui/TerminalInput.tsx @@ -180,13 +180,13 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React useEffect(() => { function keyDown(this: Document, event: KeyboardEvent): void { if (terminal.contractOpen) return; - if (terminal.action !== null && event.keyCode === KEY.C && event.ctrlKey) { + if (terminal.action !== null && event.key === KEY.c && event.ctrlKey) { terminal.finishAction(router, player, true); return; } const ref = terminalInput.current; if (event.ctrlKey || event.metaKey) return; - if (event.keyCode === KEY.C && (event.ctrlKey || event.metaKey)) return; // trying to copy + if (event.key === KEY.C && (event.ctrlKey || event.metaKey)) return; // trying to copy if (ref) ref.focus(); } @@ -196,7 +196,7 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React async function onKeyDown(event: React.KeyboardEvent): Promise { // Run command. - if (event.keyCode === KEY.ENTER && value !== "") { + if (event.key === KEY.ENTER && value !== "") { event.preventDefault(); terminal.print(`[${player.getCurrentServer().hostname} ~${terminal.cwd()}]> ${value}`); terminal.executeCommands(router, player, value); @@ -205,7 +205,7 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React } // Autocomplete - if (event.keyCode === KEY.TAB && value !== "") { + if (event.key === KEY.Tab && value !== "") { event.preventDefault(); let copy = value; @@ -256,13 +256,13 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React } // Clear screen. - if (event.keyCode === KEY.L && event.ctrlKey) { + if (event.key === KEY.L && event.ctrlKey) { event.preventDefault(); terminal.clear(); } // Select previous command. - if (event.keyCode === KEY.UPARROW || (Settings.EnableBashHotkeys && event.keyCode === KEY.P && event.ctrlKey)) { + if (event.key === KEY.UPARROW || (Settings.EnableBashHotkeys && event.key === "p" && event.ctrlKey)) { if (Settings.EnableBashHotkeys) { event.preventDefault(); } @@ -290,7 +290,7 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React } // Select next command - if (event.keyCode === KEY.DOWNARROW || (Settings.EnableBashHotkeys && event.keyCode === KEY.M && event.ctrlKey)) { + if (event.key === KEY.DOWNARROW || (Settings.EnableBashHotkeys && event.key === "m" && event.ctrlKey)) { if (Settings.EnableBashHotkeys) { event.preventDefault(); } @@ -317,57 +317,57 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React // Extra Bash Emulation Hotkeys, must be enabled through options if (Settings.EnableBashHotkeys) { - if (event.keyCode === KEY.A && event.ctrlKey) { + if (event.key === KEY.A && event.ctrlKey) { event.preventDefault(); moveTextCursor("home"); } - if (event.keyCode === KEY.E && event.ctrlKey) { + if (event.key === KEY.E && event.ctrlKey) { event.preventDefault(); moveTextCursor("end"); } - if (event.keyCode === KEY.B && event.ctrlKey) { + if (event.key === KEY.B && event.ctrlKey) { event.preventDefault(); moveTextCursor("prevchar"); } - if (event.keyCode === KEY.B && event.altKey) { + if (event.key === KEY.B && event.altKey) { event.preventDefault(); moveTextCursor("prevword"); } - if (event.keyCode === KEY.F && event.ctrlKey) { + if (event.key === KEY.F && event.ctrlKey) { event.preventDefault(); moveTextCursor("nextchar"); } - if (event.keyCode === KEY.F && event.altKey) { + if (event.key === KEY.F && event.altKey) { event.preventDefault(); moveTextCursor("nextword"); } - if ((event.keyCode === KEY.H || event.keyCode === KEY.D) && event.ctrlKey) { + if ((event.key === KEY.H || event.key === KEY.D) && event.ctrlKey) { modifyInput("backspace"); event.preventDefault(); } - if (event.keyCode === KEY.W && event.ctrlKey) { + if (event.key === KEY.W && event.ctrlKey) { event.preventDefault(); modifyInput("deletewordbefore"); } - if (event.keyCode === KEY.D && event.altKey) { + if (event.key === KEY.D && event.altKey) { event.preventDefault(); modifyInput("deletewordafter"); } - if (event.keyCode === KEY.U && event.ctrlKey) { + if (event.key === KEY.U && event.ctrlKey) { event.preventDefault(); modifyInput("clearbefore"); } - if (event.keyCode === KEY.K && event.ctrlKey) { + if (event.key === KEY.K && event.ctrlKey) { event.preventDefault(); modifyInput("clearafter"); } diff --git a/src/ui/React/CodingContractModal.tsx b/src/ui/React/CodingContractModal.tsx index 597e204e0..a16f3f61c 100644 --- a/src/ui/React/CodingContractModal.tsx +++ b/src/ui/React/CodingContractModal.tsx @@ -37,7 +37,7 @@ export function CodingContractModal(): React.ReactElement { // whatever ... const value = (event.target as any).value; - if (event.keyCode === KEY.ENTER && value !== "") { + if (event.key === KEY.ENTER && value !== "") { event.preventDefault(); props.onAttempt(answer); setAnswer(""); diff --git a/src/ui/React/PromptManager.tsx b/src/ui/React/PromptManager.tsx index 41f97e0ff..bd7145268 100644 --- a/src/ui/React/PromptManager.tsx +++ b/src/ui/React/PromptManager.tsx @@ -6,6 +6,7 @@ import Button from "@mui/material/Button"; import Select, { SelectChangeEvent } from "@mui/material/Select"; import TextField from "@mui/material/TextField"; import MenuItem from "@mui/material/MenuItem"; +import { KEY } from "../../utils/helpers/keyCodes"; export const PromptEvent = new EventEmitter<[Prompt]>(); @@ -93,7 +94,7 @@ function PromptMenuText({ resolve }: IContentProps): React.ReactElement { const onKeyDown = (event: React.KeyboardEvent): void => { event.stopPropagation(); - if (event.key === "Enter") { + if (event.key === KEY.ENTER) { event.preventDefault(); submit(); } diff --git a/src/utils/helpers/keyCodes.ts b/src/utils/helpers/keyCodes.ts index 7fc89f380..60e6c0dc1 100644 --- a/src/utils/helpers/keyCodes.ts +++ b/src/utils/helpers/keyCodes.ts @@ -3,49 +3,53 @@ import { IMap } from "../../types"; /** * Keyboard key codes */ -export const KEY: IMap = { - CTRL: 17, - DOWNARROW: 40, - ENTER: 13, - ESC: 27, - TAB: 9, - UPARROW: 38, +export const KEY: IMap = { + //SHIFT: 16, // Check by `&& event.shiftKey` + //CTRL: 17, // Check by `&& event.ctrlKey` + //ALT: 18, // Check by `&& event.altKey` + ENTER: "Enter", + ESC: "Escape", + TAB: "Tab", + UPARROW: "ArrowUp", + DOWNARROW: "ArrowDown", + LEFTARROW: "ArrowLeft", + RIGHTARROW: "ArrowRight", - "0": 48, - "1": 49, - "2": 50, - "3": 51, - "4": 52, - "5": 53, - "6": 54, - "7": 55, - "8": 56, - "9": 57, + "0": "0", + "1": "1", + "2": "2", + "3": "3", + "4": "4", + "5": "5", + "6": "6", + "7": "7", + "8": "8", + "9": "9", - A: 65, - B: 66, - C: 67, - D: 68, - E: 69, - F: 70, - G: 71, - H: 72, - I: 73, - J: 74, - K: 75, - L: 76, - M: 77, - N: 78, - O: 79, - P: 80, - Q: 81, - R: 82, - S: 83, - T: 84, - U: 85, - V: 86, - W: 87, - X: 88, - Y: 89, - Z: 90, + A: "a", + B: "b", + C: "c", + D: "d", + E: "e", + F: "f", + G: "g", + H: "h", + I: "i", + J: "j", + K: "k", + L: "l", + M: "m", + N: "n", + O: "o", + P: "p", + Q: "q", + R: "r", + S: "s", + T: "t", + U: "u", + V: "v", + W: "w", + X: "x", + Y: "y", + Z: "z", };