diff --git a/src/Bladeburner/ui/Console.tsx b/src/Bladeburner/ui/Console.tsx index c64957714..e0bd03f14 100644 --- a/src/Bladeburner/ui/Console.tsx +++ b/src/Bladeburner/ui/Console.tsx @@ -76,7 +76,7 @@ export function Console(props: IProps): React.ReactElement { }, []); function handleKeyDown(event: React.KeyboardEvent): void { - if (event.keyCode === 13) { + if (event.key === "Enter") { event.preventDefault(); if (command.length > 0) { props.bladeburner.postToConsole("> " + command); @@ -88,7 +88,7 @@ export function Console(props: IProps): React.ReactElement { const consoleHistory = props.bladeburner.consoleHistory; - if (event.keyCode === 38) { + if (event.key === "s") { // up let i = consoleHistoryIndex; const len = consoleHistory.length; @@ -108,7 +108,7 @@ export function Console(props: IProps): React.ReactElement { setCommand(prevCommand); } - if (event.keyCode === 40) { + if (event.key === "ArrowDown") { const i = consoleHistoryIndex; const len = consoleHistory.length; diff --git a/src/Corporation/ui/BuybackSharesModal.tsx b/src/Corporation/ui/BuybackSharesModal.tsx index 4d6568af7..579dd2992 100644 --- a/src/Corporation/ui/BuybackSharesModal.tsx +++ b/src/Corporation/ui/BuybackSharesModal.tsx @@ -69,7 +69,7 @@ export function BuybackSharesModal(props: IProps): React.ReactElement { } function onKeyDown(event: React.KeyboardEvent): void { - if (event.keyCode === 13) buy(); + if (event.key === "Enter") buy(); } return ( diff --git a/src/Corporation/ui/ExpandIndustryTab.tsx b/src/Corporation/ui/ExpandIndustryTab.tsx index 8477a8a76..e16f097f2 100644 --- a/src/Corporation/ui/ExpandIndustryTab.tsx +++ b/src/Corporation/ui/ExpandIndustryTab.tsx @@ -53,7 +53,7 @@ export function ExpandIndustryTab(props: IProps): React.ReactElement { } function onKeyDown(event: React.KeyboardEvent): void { - if (event.keyCode === 13) newIndustry(); + if (event.key === "Enter") newIndustry(); } function onIndustryChange(event: SelectChangeEvent): void { diff --git a/src/Corporation/ui/GoPublicModal.tsx b/src/Corporation/ui/GoPublicModal.tsx index 5d093cf8c..9a20d7213 100644 --- a/src/Corporation/ui/GoPublicModal.tsx +++ b/src/Corporation/ui/GoPublicModal.tsx @@ -45,7 +45,7 @@ export function GoPublicModal(props: IProps): React.ReactElement { } function onKeyDown(event: React.KeyboardEvent): void { - if (event.keyCode === 13) goPublic(); + if (event.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..e8cbe36ab 100644 --- a/src/Corporation/ui/IssueDividendsModal.tsx +++ b/src/Corporation/ui/IssueDividendsModal.tsx @@ -32,7 +32,7 @@ export function IssueDividendsModal(props: IProps): React.ReactElement { } function onKeyDown(event: React.KeyboardEvent): void { - if (event.keyCode === 13) issueDividends(); + if (event.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..b7534f18c 100644 --- a/src/Corporation/ui/IssueNewSharesModal.tsx +++ b/src/Corporation/ui/IssueNewSharesModal.tsx @@ -93,7 +93,7 @@ export function IssueNewSharesModal(props: IProps): React.ReactElement { } function onKeyDown(event: React.KeyboardEvent): void { - if (event.keyCode === 13) issueNewShares(); + if (event.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..cc6c3e4e6 100644 --- a/src/Corporation/ui/LimitProductProductionModal.tsx +++ b/src/Corporation/ui/LimitProductProductionModal.tsx @@ -25,7 +25,7 @@ export function LimitProductProductionModal(props: IProps): React.ReactElement { } function onKeyDown(event: React.KeyboardEvent): void { - if (event.keyCode === 13) limitProductProduction(); + if (event.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..44c1afeec 100644 --- a/src/Corporation/ui/MakeProductModal.tsx +++ b/src/Corporation/ui/MakeProductModal.tsx @@ -165,7 +165,7 @@ export function MakeProductModal(props: IProps): React.ReactElement { } function onKeyDown(event: React.KeyboardEvent): void { - if (event.keyCode === 13) makeProduct(); + if (event.key === "Enter") makeProduct(); } return ( diff --git a/src/Corporation/ui/PurchaseMaterialModal.tsx b/src/Corporation/ui/PurchaseMaterialModal.tsx index 5c6f6bda8..7891c56a3 100644 --- a/src/Corporation/ui/PurchaseMaterialModal.tsx +++ b/src/Corporation/ui/PurchaseMaterialModal.tsx @@ -68,7 +68,7 @@ function BulkPurchaseSection(props: IBPProps): React.ReactElement { } function onKeyDown(event: React.KeyboardEvent): void { - if (event.keyCode === 13) bulkPurchase(); + if (event.key === "Enter") bulkPurchase(); } function onChange(event: React.ChangeEvent): void { @@ -123,7 +123,7 @@ export function PurchaseMaterialModal(props: IProps): React.ReactElement { } function onKeyDown(event: React.KeyboardEvent): void { - if (event.keyCode === 13) purchaseMaterial(); + if (event.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..00f187ed3 100644 --- a/src/Corporation/ui/SellMaterialModal.tsx +++ b/src/Corporation/ui/SellMaterialModal.tsx @@ -46,7 +46,7 @@ export function SellMaterialModal(props: IProps): React.ReactElement { } function onKeyDown(event: React.KeyboardEvent): void { - if (event.keyCode === 13) sellMaterial(); + if (event.key === "Enter") sellMaterial(); } return ( diff --git a/src/Corporation/ui/SellProductModal.tsx b/src/Corporation/ui/SellProductModal.tsx index 5b383a583..1f00fba69 100644 --- a/src/Corporation/ui/SellProductModal.tsx +++ b/src/Corporation/ui/SellProductModal.tsx @@ -58,7 +58,7 @@ export function SellProductModal(props: IProps): React.ReactElement { } function onKeyDown(event: React.KeyboardEvent): void { - if (event.keyCode === 13) sellProduct(); + if (event.key === "Enter") sellProduct(); } return ( diff --git a/src/Corporation/ui/SellSharesModal.tsx b/src/Corporation/ui/SellSharesModal.tsx index e96fa9959..b25307678 100644 --- a/src/Corporation/ui/SellSharesModal.tsx +++ b/src/Corporation/ui/SellSharesModal.tsx @@ -68,7 +68,7 @@ export function SellSharesModal(props: IProps): React.ReactElement { } function onKeyDown(event: React.KeyboardEvent): void { - if (event.keyCode === 13) sell(); + if (event.key === "Enter") sell(); } return ( diff --git a/src/Corporation/ui/ThrowPartyModal.tsx b/src/Corporation/ui/ThrowPartyModal.tsx index 8b89c4506..0257b3017 100644 --- a/src/Corporation/ui/ThrowPartyModal.tsx +++ b/src/Corporation/ui/ThrowPartyModal.tsx @@ -57,7 +57,7 @@ export function ThrowPartyModal(props: IProps): React.ReactElement { } function onKeyDown(event: React.KeyboardEvent): void { - if (event.keyCode === 13) throwParty(); + if (event.key === "Enter") throwParty(); } return ( diff --git a/src/Faction/ui/CreateGangModal.tsx b/src/Faction/ui/CreateGangModal.tsx index c2592286f..085ee3fb6 100644 --- a/src/Faction/ui/CreateGangModal.tsx +++ b/src/Faction/ui/CreateGangModal.tsx @@ -37,7 +37,7 @@ export function CreateGangModal(props: IProps): React.ReactElement { } function onKeyUp(event: React.KeyboardEvent): void { - if (event.keyCode === 13) createGang(); + if (event.key === "Enter") createGang(); } return ( diff --git a/src/Gang/ui/RecruitModal.tsx b/src/Gang/ui/RecruitModal.tsx index c5096ba74..15b6d6558 100644 --- a/src/Gang/ui/RecruitModal.tsx +++ b/src/Gang/ui/RecruitModal.tsx @@ -34,7 +34,7 @@ export function RecruitModal(props: IRecruitPopupProps): React.ReactElement { } function onKeyUp(event: React.KeyboardEvent): void { - if (event.keyCode === 13) recruit(); + if (event.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..e4c8204a9 100644 --- a/src/Locations/ui/PurchaseServerModal.tsx +++ b/src/Locations/ui/PurchaseServerModal.tsx @@ -29,7 +29,7 @@ export function PurchaseServerModal(props: IProps): React.ReactElement { } function onKeyUp(event: React.KeyboardEvent): void { - if (event.keyCode === 13) tryToPurchaseServer(); + if (event.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..a300ea7e6 100644 --- a/src/Sidebar/ui/SidebarRoot.tsx +++ b/src/Sidebar/ui/SidebarRoot.tsx @@ -53,7 +53,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 +275,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 === "c" && event.altKey) { event.preventDefault(); clickStats(); - } else if (event.keyCode === KEY.E && event.altKey) { + } else if (event.key === "e" && event.altKey) { event.preventDefault(); clickScriptEditor(); - } else if (event.keyCode === KEY.S && event.altKey) { + } else if (event.key === "s" && event.altKey) { event.preventDefault(); clickActiveScripts(); - } else if (event.keyCode === KEY.H && event.altKey) { + } else if (event.key === "h" && event.altKey) { event.preventDefault(); clickHacknet(); - } else if (event.keyCode === KEY.W && event.altKey) { + } else if (event.key === "w" && event.altKey) { event.preventDefault(); clickCity(); - } else if (event.keyCode === KEY.J && event.altKey && !event.ctrlKey && !event.metaKey && canJob) { + } else if (event.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 === "r" && event.altKey) { event.preventDefault(); clickTravel(); - } else if (event.keyCode === KEY.P && event.altKey) { + } else if (event.key === "p" && event.altKey) { event.preventDefault(); clickCreateProgram(); - } else if (event.keyCode === KEY.F && event.altKey) { + } else if (event.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 === "a" && event.altKey) { event.preventDefault(); clickAugmentations(); - } else if (event.keyCode === KEY.U && event.altKey) { + } else if (event.key === "u" && event.altKey) { event.preventDefault(); clickTutorial(); - } else if (event.keyCode === KEY.B && event.altKey && props.player.bladeburner) { + } else if (event.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 === "g" && event.altKey && props.player.gang) { event.preventDefault(); clickGang(); } - // if (event.keyCode === KEY.O && event.altKey) { + // if (event.key === "o" && event.altKey) { // event.preventDefault(); // gameOptionsBoxOpen(); // } diff --git a/src/Terminal/ui/TerminalInput.tsx b/src/Terminal/ui/TerminalInput.tsx index 318a77765..48491b82d 100644 --- a/src/Terminal/ui/TerminalInput.tsx +++ b/src/Terminal/ui/TerminalInput.tsx @@ -6,7 +6,6 @@ import createStyles from "@mui/styles/createStyles"; import TextField from "@mui/material/TextField"; import Tooltip from "@mui/material/Tooltip"; -import { KEY } from "../../utils/helpers/keyCodes"; import { ITerminal } from "../ITerminal"; import { IRouter } from "../../ui/Router"; import { IPlayer } from "../../PersonObjects/IPlayer"; @@ -180,13 +179,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 === "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 === "c" && (event.ctrlKey || event.metaKey)) return; // trying to copy if (ref) ref.focus(); } @@ -196,7 +195,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 === "Enter" && value !== "") { event.preventDefault(); terminal.print(`[${player.getCurrentServer().hostname} ~${terminal.cwd()}]> ${value}`); terminal.executeCommands(router, player, value); @@ -205,7 +204,7 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React } // Autocomplete - if (event.keyCode === KEY.TAB && value !== "") { + if (event.key === "Tab" && value !== "") { event.preventDefault(); let copy = value; @@ -256,13 +255,13 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React } // Clear screen. - if (event.keyCode === KEY.L && event.ctrlKey) { + if (event.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 === "ArrowUp" || (Settings.EnableBashHotkeys && event.key === "p" && event.ctrlKey)) { if (Settings.EnableBashHotkeys) { event.preventDefault(); } @@ -290,7 +289,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 === "ArrowDown" || (Settings.EnableBashHotkeys && event.key === "m" && event.ctrlKey)) { if (Settings.EnableBashHotkeys) { event.preventDefault(); } @@ -317,57 +316,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 === "a" && event.ctrlKey) { event.preventDefault(); moveTextCursor("home"); } - if (event.keyCode === KEY.E && event.ctrlKey) { + if (event.key === "e" && event.ctrlKey) { event.preventDefault(); moveTextCursor("end"); } - if (event.keyCode === KEY.B && event.ctrlKey) { + if (event.key === "b" && event.ctrlKey) { event.preventDefault(); moveTextCursor("prevchar"); } - if (event.keyCode === KEY.B && event.altKey) { + if (event.key === "b" && event.altKey) { event.preventDefault(); moveTextCursor("prevword"); } - if (event.keyCode === KEY.F && event.ctrlKey) { + if (event.key === "f" && event.ctrlKey) { event.preventDefault(); moveTextCursor("nextchar"); } - if (event.keyCode === KEY.F && event.altKey) { + if (event.key === "f" && event.altKey) { event.preventDefault(); moveTextCursor("nextword"); } - if ((event.keyCode === KEY.H || event.keyCode === KEY.D) && event.ctrlKey) { + if ((event.key === "h" || event.key === "d") && event.ctrlKey) { modifyInput("backspace"); event.preventDefault(); } - if (event.keyCode === KEY.W && event.ctrlKey) { + if (event.key === "w" && event.ctrlKey) { event.preventDefault(); modifyInput("deletewordbefore"); } - if (event.keyCode === KEY.D && event.altKey) { + if (event.key === "d" && event.altKey) { event.preventDefault(); modifyInput("deletewordafter"); } - if (event.keyCode === KEY.U && event.ctrlKey) { + if (event.key === "u" && event.ctrlKey) { event.preventDefault(); modifyInput("clearbefore"); } - if (event.keyCode === KEY.K && event.ctrlKey) { + if (event.key === "k" && event.ctrlKey) { event.preventDefault(); modifyInput("clearafter"); } diff --git a/src/ui/React/CodingContractModal.tsx b/src/ui/React/CodingContractModal.tsx index 597e204e0..490922bfd 100644 --- a/src/ui/React/CodingContractModal.tsx +++ b/src/ui/React/CodingContractModal.tsx @@ -1,5 +1,4 @@ import React, { useState, useEffect } from "react"; -import { KEY } from "../../utils/helpers/keyCodes"; import { CodingContract, CodingContractTypes } from "../../CodingContracts"; import { CopyableText } from "./CopyableText"; @@ -37,7 +36,7 @@ export function CodingContractModal(): React.ReactElement { // whatever ... const value = (event.target as any).value; - if (event.keyCode === KEY.ENTER && value !== "") { + if (event.key === "Enter" && value !== "") { event.preventDefault(); props.onAttempt(answer); setAnswer("");