Merge pull request #3156 from Master-Guy/issues/2308

Changed .keyCode to .key for files in "src"
This commit is contained in:
hydroflame 2022-03-20 14:22:38 -04:00 committed by GitHub
commit 1a339a9611
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 119 additions and 98 deletions

@ -1,5 +1,6 @@
import React, { useState, useRef, useEffect } from "react"; import React, { useState, useRef, useEffect } from "react";
import { IBladeburner } from "../IBladeburner"; import { IBladeburner } from "../IBladeburner";
import { KEY } from "../../utils/helpers/keyCodes";
import { IPlayer } from "../../PersonObjects/IPlayer"; import { IPlayer } from "../../PersonObjects/IPlayer";
import Paper from "@mui/material/Paper"; import Paper from "@mui/material/Paper";
@ -76,7 +77,7 @@ export function Console(props: IProps): React.ReactElement {
}, []); }, []);
function handleKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void { function handleKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {
if (event.keyCode === 13) { if (event.key === KEY.ENTER) {
event.preventDefault(); event.preventDefault();
if (command.length > 0) { if (command.length > 0) {
props.bladeburner.postToConsole("> " + command); props.bladeburner.postToConsole("> " + command);
@ -88,7 +89,7 @@ export function Console(props: IProps): React.ReactElement {
const consoleHistory = props.bladeburner.consoleHistory; const consoleHistory = props.bladeburner.consoleHistory;
if (event.keyCode === 38) { if (event.key === KEY.S) {
// up // up
let i = consoleHistoryIndex; let i = consoleHistoryIndex;
const len = consoleHistory.length; const len = consoleHistory.length;
@ -108,7 +109,7 @@ export function Console(props: IProps): React.ReactElement {
setCommand(prevCommand); setCommand(prevCommand);
} }
if (event.keyCode === 40) { if (event.key === KEY.DOWNARROW) {
const i = consoleHistoryIndex; const i = consoleHistoryIndex;
const len = consoleHistory.length; const len = consoleHistory.length;

@ -8,6 +8,7 @@ import Button from "@mui/material/Button";
import TextField from "@mui/material/TextField"; import TextField from "@mui/material/TextField";
import { BuyBackShares } from '../Actions'; import { BuyBackShares } from '../Actions';
import { dialogBoxCreate } from '../../ui/React/DialogBox'; import { dialogBoxCreate } from '../../ui/React/DialogBox';
import { KEY } from "../../utils/helpers/keyCodes";
interface IProps { interface IProps {
open: boolean; open: boolean;
@ -69,7 +70,7 @@ export function BuybackSharesModal(props: IProps): React.ReactElement {
} }
function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void { function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {
if (event.keyCode === 13) buy(); if (event.key === KEY.ENTER) buy();
} }
return ( return (

@ -11,6 +11,7 @@ import TextField from "@mui/material/TextField";
import MenuItem from "@mui/material/MenuItem"; import MenuItem from "@mui/material/MenuItem";
import Box from "@mui/material/Box"; import Box from "@mui/material/Box";
import Select, { SelectChangeEvent } from "@mui/material/Select"; import Select, { SelectChangeEvent } from "@mui/material/Select";
import { KEY } from "../../utils/helpers/keyCodes";
interface IProps { interface IProps {
setDivisionName: (name: string) => void; setDivisionName: (name: string) => void;
@ -53,7 +54,7 @@ export function ExpandIndustryTab(props: IProps): React.ReactElement {
} }
function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void { function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {
if (event.keyCode === 13) newIndustry(); if (event.key === KEY.ENTER) newIndustry();
} }
function onIndustryChange(event: SelectChangeEvent<string>): void { function onIndustryChange(event: SelectChangeEvent<string>): void {

@ -7,6 +7,7 @@ import Typography from "@mui/material/Typography";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
import TextField from "@mui/material/TextField"; import TextField from "@mui/material/TextField";
import Box from "@mui/material/Box"; import Box from "@mui/material/Box";
import { KEY } from "../../utils/helpers/keyCodes";
interface IProps { interface IProps {
open: boolean; open: boolean;
@ -45,7 +46,7 @@ export function GoPublicModal(props: IProps): React.ReactElement {
} }
function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void { function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {
if (event.keyCode === 13) goPublic(); if (event.key === KEY.ENTER) goPublic();
} }
function onChange(event: React.ChangeEvent<HTMLInputElement>): void { function onChange(event: React.ChangeEvent<HTMLInputElement>): void {

@ -7,6 +7,7 @@ import { useCorporation } from "./Context";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import TextField from "@mui/material/TextField"; import TextField from "@mui/material/TextField";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
import { KEY } from "../../utils/helpers/keyCodes";
interface IProps { interface IProps {
open: boolean; open: boolean;
onClose: () => void; onClose: () => void;
@ -32,7 +33,7 @@ export function IssueDividendsModal(props: IProps): React.ReactElement {
} }
function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void { function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {
if (event.keyCode === 13) issueDividends(); if (event.key === KEY.ENTER) issueDividends();
} }
function onChange(event: React.ChangeEvent<HTMLInputElement>): void { function onChange(event: React.ChangeEvent<HTMLInputElement>): void {

@ -8,6 +8,7 @@ import { useCorporation } from "./Context";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import TextField from "@mui/material/TextField"; import TextField from "@mui/material/TextField";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
import { KEY } from "../../utils/helpers/keyCodes";
interface IEffectTextProps { interface IEffectTextProps {
shares: number | null; shares: number | null;
@ -93,7 +94,7 @@ export function IssueNewSharesModal(props: IProps): React.ReactElement {
} }
function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void { function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {
if (event.keyCode === 13) issueNewShares(); if (event.key === KEY.ENTER) issueNewShares();
} }
function onChange(event: React.ChangeEvent<HTMLInputElement>): void { function onChange(event: React.ChangeEvent<HTMLInputElement>): void {

@ -5,6 +5,7 @@ import { Modal } from "../../ui/React/Modal";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
import TextField from "@mui/material/TextField"; import TextField from "@mui/material/TextField";
import { KEY } from "../../utils/helpers/keyCodes";
interface IProps { interface IProps {
open: boolean; open: boolean;
@ -25,7 +26,7 @@ export function LimitProductProductionModal(props: IProps): React.ReactElement {
} }
function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void { function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {
if (event.keyCode === 13) limitProductProduction(); if (event.key === KEY.ENTER) limitProductProduction();
} }
function onChange(event: React.ChangeEvent<HTMLInputElement>): void { function onChange(event: React.ChangeEvent<HTMLInputElement>): void {

@ -9,6 +9,7 @@ import TextField from "@mui/material/TextField";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
import MenuItem from "@mui/material/MenuItem"; import MenuItem from "@mui/material/MenuItem";
import Select, { SelectChangeEvent } from "@mui/material/Select"; import Select, { SelectChangeEvent } from "@mui/material/Select";
import { KEY } from "../../utils/helpers/keyCodes";
interface IProps { interface IProps {
open: boolean; open: boolean;
@ -165,7 +166,7 @@ export function MakeProductModal(props: IProps): React.ReactElement {
} }
function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void { function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {
if (event.keyCode === 13) makeProduct(); if (event.key === KEY.ENTER) makeProduct();
} }
return ( return (

@ -10,6 +10,7 @@ import { useCorporation, useDivision } from "./Context";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import TextField from "@mui/material/TextField"; import TextField from "@mui/material/TextField";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
import { KEY } from "../../utils/helpers/keyCodes";
interface IBulkPurchaseTextProps { interface IBulkPurchaseTextProps {
warehouse: Warehouse; warehouse: Warehouse;
@ -68,7 +69,7 @@ function BulkPurchaseSection(props: IBPProps): React.ReactElement {
} }
function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void { function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {
if (event.keyCode === 13) bulkPurchase(); if (event.key === KEY.ENTER) bulkPurchase();
} }
function onChange(event: React.ChangeEvent<HTMLInputElement>): void { function onChange(event: React.ChangeEvent<HTMLInputElement>): void {
@ -123,7 +124,7 @@ export function PurchaseMaterialModal(props: IProps): React.ReactElement {
} }
function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void { function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {
if (event.keyCode === 13) purchaseMaterial(); if (event.key === KEY.ENTER) purchaseMaterial();
} }
function onChange(event: React.ChangeEvent<HTMLInputElement>): void { function onChange(event: React.ChangeEvent<HTMLInputElement>): void {

@ -6,6 +6,7 @@ import { Modal } from "../../ui/React/Modal";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import TextField from "@mui/material/TextField"; import TextField from "@mui/material/TextField";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
import { KEY } from "../../utils/helpers/keyCodes";
function initialPrice(mat: Material): string { function initialPrice(mat: Material): string {
let val = mat.sCost ? mat.sCost + "" : ""; let val = mat.sCost ? mat.sCost + "" : "";
@ -46,7 +47,7 @@ export function SellMaterialModal(props: IProps): React.ReactElement {
} }
function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void { function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {
if (event.keyCode === 13) sellMaterial(); if (event.key === KEY.ENTER) sellMaterial();
} }
return ( return (

@ -9,6 +9,7 @@ import TextField from "@mui/material/TextField";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
import FormControlLabel from "@mui/material/FormControlLabel"; import FormControlLabel from "@mui/material/FormControlLabel";
import Switch from "@mui/material/Switch"; import Switch from "@mui/material/Switch";
import { KEY } from "../../utils/helpers/keyCodes";
function initialPrice(product: Product): string { function initialPrice(product: Product): string {
let val = product.sCost ? product.sCost + "" : ""; let val = product.sCost ? product.sCost + "" : "";
@ -58,7 +59,7 @@ export function SellProductModal(props: IProps): React.ReactElement {
} }
function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void { function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {
if (event.keyCode === 13) sellProduct(); if (event.key === KEY.ENTER) sellProduct();
} }
return ( return (

@ -10,6 +10,7 @@ import TextField from "@mui/material/TextField";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
import { Money } from "../../ui/React/Money"; import { Money } from "../../ui/React/Money";
import { SellShares } from "../Actions"; import { SellShares } from "../Actions";
import { KEY } from "../../utils/helpers/keyCodes";
interface IProps { interface IProps {
open: boolean; open: boolean;
onClose: () => void; onClose: () => void;
@ -68,7 +69,7 @@ export function SellSharesModal(props: IProps): React.ReactElement {
} }
function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void { function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {
if (event.keyCode === 13) sell(); if (event.key === KEY.ENTER) sell();
} }
return ( return (

@ -10,6 +10,7 @@ import Typography from "@mui/material/Typography";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
import TextField from "@mui/material/TextField"; import TextField from "@mui/material/TextField";
import Box from "@mui/material/Box"; import Box from "@mui/material/Box";
import { KEY } from "../../utils/helpers/keyCodes";
interface IProps { interface IProps {
open: boolean; open: boolean;
@ -57,7 +58,7 @@ export function ThrowPartyModal(props: IProps): React.ReactElement {
} }
function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void { function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {
if (event.keyCode === 13) throwParty(); if (event.key === KEY.ENTER) throwParty();
} }
return ( return (

@ -6,6 +6,7 @@ import { Modal } from "../../ui/React/Modal";
import { use } from "../../ui/Context"; import { use } from "../../ui/Context";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
import { KEY } from "../../utils/helpers/keyCodes";
import { FactionNames } from "../data/FactionNames"; import { FactionNames } from "../data/FactionNames";
interface IProps { interface IProps {
@ -38,7 +39,7 @@ export function CreateGangModal(props: IProps): React.ReactElement {
} }
function onKeyUp(event: React.KeyboardEvent): void { function onKeyUp(event: React.KeyboardEvent): void {
if (event.keyCode === 13) createGang(); if (event.key === KEY.ENTER) createGang();
} }
return ( return (

@ -8,6 +8,7 @@ import { useGang } from "./Context";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import TextField from "@mui/material/TextField"; import TextField from "@mui/material/TextField";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
import { KEY } from "../../utils/helpers/keyCodes";
interface IRecruitPopupProps { interface IRecruitPopupProps {
open: boolean; open: boolean;
@ -34,7 +35,7 @@ export function RecruitModal(props: IRecruitPopupProps): React.ReactElement {
} }
function onKeyUp(event: React.KeyboardEvent<HTMLInputElement>): void { function onKeyUp(event: React.KeyboardEvent<HTMLInputElement>): void {
if (event.keyCode === 13) recruit(); if (event.key === KEY.ENTER) recruit();
} }
function onChange(event: React.ChangeEvent<HTMLInputElement>): void { function onChange(event: React.ChangeEvent<HTMLInputElement>): void {

@ -10,6 +10,7 @@ import { use } from "../../ui/Context";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import TextField from "@mui/material/TextField"; import TextField from "@mui/material/TextField";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
import { KEY } from "../../utils/helpers/keyCodes";
interface IProps { interface IProps {
open: boolean; open: boolean;
@ -29,7 +30,7 @@ export function PurchaseServerModal(props: IProps): React.ReactElement {
} }
function onKeyUp(event: React.KeyboardEvent<HTMLInputElement>): void { function onKeyUp(event: React.KeyboardEvent<HTMLInputElement>): void {
if (event.keyCode === 13) tryToPurchaseServer(); if (event.key === KEY.ENTER) tryToPurchaseServer();
} }
function onChange(event: React.ChangeEvent<HTMLInputElement>): void { function onChange(event: React.ChangeEvent<HTMLInputElement>): void {

@ -1,4 +1,5 @@
import React, { useState, useEffect } from "react"; import React, { useState, useEffect } from "react";
import { KEY } from "../../utils/helpers/keyCodes";
import clsx from "clsx"; import clsx from "clsx";
import { styled, Theme, CSSObject } from "@mui/material/styles"; import { styled, Theme, CSSObject } from "@mui/material/styles";
import createStyles from "@mui/styles/createStyles"; import createStyles from "@mui/styles/createStyles";
@ -53,7 +54,6 @@ import { Settings } from "../../Settings/Settings";
import { redPillFlag } from "../../RedPill"; import { redPillFlag } from "../../RedPill";
import { AugmentationNames } from "../../Augmentation/data/AugmentationNames"; import { AugmentationNames } from "../../Augmentation/data/AugmentationNames";
import { KEY } from "../../utils/helpers/keyCodes";
import { ProgramsSeen } from "../../Programs/ui/ProgramsRoot"; import { ProgramsSeen } from "../../Programs/ui/ProgramsRoot";
import { InvitationsSeen } from "../../Faction/ui/FactionsRoot"; import { InvitationsSeen } from "../../Faction/ui/FactionsRoot";
import { hash } from "../../hash/hash"; import { hash } from "../../hash/hash";
@ -276,54 +276,54 @@ export function SidebarRoot(props: IProps): React.ReactElement {
function handleShortcuts(this: Document, event: KeyboardEvent): any { function handleShortcuts(this: Document, event: KeyboardEvent): any {
if (Settings.DisableHotkeys) return; if (Settings.DisableHotkeys) return;
if ((props.player.isWorking && props.player.focus) || redPillFlag) 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(); event.preventDefault();
clickTerminal(); clickTerminal();
} else if (event.keyCode === KEY.C && event.altKey) { } else if (event.key === KEY.C && event.altKey) {
event.preventDefault(); event.preventDefault();
clickStats(); clickStats();
} else if (event.keyCode === KEY.E && event.altKey) { } else if (event.key === KEY.E && event.altKey) {
event.preventDefault(); event.preventDefault();
clickScriptEditor(); clickScriptEditor();
} else if (event.keyCode === KEY.S && event.altKey) { } else if (event.key === KEY.S && event.altKey) {
event.preventDefault(); event.preventDefault();
clickActiveScripts(); clickActiveScripts();
} else if (event.keyCode === KEY.H && event.altKey) { } else if (event.key === KEY.H && event.altKey) {
event.preventDefault(); event.preventDefault();
clickHacknet(); clickHacknet();
} else if (event.keyCode === KEY.W && event.altKey) { } else if (event.key === KEY.W && event.altKey) {
event.preventDefault(); event.preventDefault();
clickCity(); 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 // ctrl/cmd + alt + j is shortcut to open Chrome dev tools
event.preventDefault(); event.preventDefault();
clickJob(); clickJob();
} else if (event.keyCode === KEY.R && event.altKey) { } else if (event.key === KEY.R && event.altKey) {
event.preventDefault(); event.preventDefault();
clickTravel(); clickTravel();
} else if (event.keyCode === KEY.P && event.altKey) { } else if (event.key === KEY.P && event.altKey) {
event.preventDefault(); event.preventDefault();
clickCreateProgram(); clickCreateProgram();
} else if (event.keyCode === KEY.F && event.altKey) { } else if (event.key === KEY.F && event.altKey) {
if (props.page == Page.Terminal && Settings.EnableBashHotkeys) { if (props.page == Page.Terminal && Settings.EnableBashHotkeys) {
return; return;
} }
event.preventDefault(); event.preventDefault();
clickFactions(); clickFactions();
} else if (event.keyCode === KEY.A && event.altKey) { } else if (event.key === KEY.A && event.altKey) {
event.preventDefault(); event.preventDefault();
clickAugmentations(); clickAugmentations();
} else if (event.keyCode === KEY.U && event.altKey) { } else if (event.key === KEY.U && event.altKey) {
event.preventDefault(); event.preventDefault();
clickTutorial(); 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(); event.preventDefault();
clickBladeburner(); 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(); event.preventDefault();
clickGang(); clickGang();
} }
// if (event.keyCode === KEY.O && event.altKey) { // if (event.key === KEY.O && event.altKey) {
// event.preventDefault(); // event.preventDefault();
// gameOptionsBoxOpen(); // gameOptionsBoxOpen();
// } // }

@ -180,13 +180,13 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React
useEffect(() => { useEffect(() => {
function keyDown(this: Document, event: KeyboardEvent): void { function keyDown(this: Document, event: KeyboardEvent): void {
if (terminal.contractOpen) return; 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); terminal.finishAction(router, player, true);
return; return;
} }
const ref = terminalInput.current; const ref = terminalInput.current;
if (event.ctrlKey || event.metaKey) return; 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(); if (ref) ref.focus();
} }
@ -196,7 +196,7 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React
async function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): Promise<void> { async function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): Promise<void> {
// Run command. // Run command.
if (event.keyCode === KEY.ENTER && value !== "") { if (event.key === KEY.ENTER && value !== "") {
event.preventDefault(); event.preventDefault();
terminal.print(`[${player.getCurrentServer().hostname} ~${terminal.cwd()}]> ${value}`); terminal.print(`[${player.getCurrentServer().hostname} ~${terminal.cwd()}]> ${value}`);
terminal.executeCommands(router, player, value); terminal.executeCommands(router, player, value);
@ -205,7 +205,7 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React
} }
// Autocomplete // Autocomplete
if (event.keyCode === KEY.TAB && value !== "") { if (event.key === KEY.Tab && value !== "") {
event.preventDefault(); event.preventDefault();
let copy = value; let copy = value;
@ -256,13 +256,13 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React
} }
// Clear screen. // Clear screen.
if (event.keyCode === KEY.L && event.ctrlKey) { if (event.key === KEY.L && event.ctrlKey) {
event.preventDefault(); event.preventDefault();
terminal.clear(); terminal.clear();
} }
// Select previous command. // 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) { if (Settings.EnableBashHotkeys) {
event.preventDefault(); event.preventDefault();
} }
@ -290,7 +290,7 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React
} }
// Select next command // 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) { if (Settings.EnableBashHotkeys) {
event.preventDefault(); event.preventDefault();
} }
@ -317,57 +317,57 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React
// Extra Bash Emulation Hotkeys, must be enabled through options // Extra Bash Emulation Hotkeys, must be enabled through options
if (Settings.EnableBashHotkeys) { if (Settings.EnableBashHotkeys) {
if (event.keyCode === KEY.A && event.ctrlKey) { if (event.key === KEY.A && event.ctrlKey) {
event.preventDefault(); event.preventDefault();
moveTextCursor("home"); moveTextCursor("home");
} }
if (event.keyCode === KEY.E && event.ctrlKey) { if (event.key === KEY.E && event.ctrlKey) {
event.preventDefault(); event.preventDefault();
moveTextCursor("end"); moveTextCursor("end");
} }
if (event.keyCode === KEY.B && event.ctrlKey) { if (event.key === KEY.B && event.ctrlKey) {
event.preventDefault(); event.preventDefault();
moveTextCursor("prevchar"); moveTextCursor("prevchar");
} }
if (event.keyCode === KEY.B && event.altKey) { if (event.key === KEY.B && event.altKey) {
event.preventDefault(); event.preventDefault();
moveTextCursor("prevword"); moveTextCursor("prevword");
} }
if (event.keyCode === KEY.F && event.ctrlKey) { if (event.key === KEY.F && event.ctrlKey) {
event.preventDefault(); event.preventDefault();
moveTextCursor("nextchar"); moveTextCursor("nextchar");
} }
if (event.keyCode === KEY.F && event.altKey) { if (event.key === KEY.F && event.altKey) {
event.preventDefault(); event.preventDefault();
moveTextCursor("nextword"); 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"); modifyInput("backspace");
event.preventDefault(); event.preventDefault();
} }
if (event.keyCode === KEY.W && event.ctrlKey) { if (event.key === KEY.W && event.ctrlKey) {
event.preventDefault(); event.preventDefault();
modifyInput("deletewordbefore"); modifyInput("deletewordbefore");
} }
if (event.keyCode === KEY.D && event.altKey) { if (event.key === KEY.D && event.altKey) {
event.preventDefault(); event.preventDefault();
modifyInput("deletewordafter"); modifyInput("deletewordafter");
} }
if (event.keyCode === KEY.U && event.ctrlKey) { if (event.key === KEY.U && event.ctrlKey) {
event.preventDefault(); event.preventDefault();
modifyInput("clearbefore"); modifyInput("clearbefore");
} }
if (event.keyCode === KEY.K && event.ctrlKey) { if (event.key === KEY.K && event.ctrlKey) {
event.preventDefault(); event.preventDefault();
modifyInput("clearafter"); modifyInput("clearafter");
} }

@ -37,7 +37,7 @@ export function CodingContractModal(): React.ReactElement {
// whatever ... // whatever ...
const value = (event.target as any).value; const value = (event.target as any).value;
if (event.keyCode === KEY.ENTER && value !== "") { if (event.key === KEY.ENTER && value !== "") {
event.preventDefault(); event.preventDefault();
props.onAttempt(answer); props.onAttempt(answer);
setAnswer(""); setAnswer("");

@ -6,6 +6,7 @@ import Button from "@mui/material/Button";
import Select, { SelectChangeEvent } from "@mui/material/Select"; import Select, { SelectChangeEvent } from "@mui/material/Select";
import TextField from "@mui/material/TextField"; import TextField from "@mui/material/TextField";
import MenuItem from "@mui/material/MenuItem"; import MenuItem from "@mui/material/MenuItem";
import { KEY } from "../../utils/helpers/keyCodes";
export const PromptEvent = new EventEmitter<[Prompt]>(); export const PromptEvent = new EventEmitter<[Prompt]>();
@ -93,7 +94,7 @@ function PromptMenuText({ resolve }: IContentProps): React.ReactElement {
const onKeyDown = (event: React.KeyboardEvent<HTMLInputElement>): void => { const onKeyDown = (event: React.KeyboardEvent<HTMLInputElement>): void => {
event.stopPropagation(); event.stopPropagation();
if (event.key === "Enter") { if (event.key === KEY.ENTER) {
event.preventDefault(); event.preventDefault();
submit(); submit();
} }

@ -3,49 +3,53 @@ import { IMap } from "../../types";
/** /**
* Keyboard key codes * Keyboard key codes
*/ */
export const KEY: IMap<number> = { export const KEY: IMap<string> = {
CTRL: 17, //SHIFT: 16, // Check by `&& event.shiftKey`
DOWNARROW: 40, //CTRL: 17, // Check by `&& event.ctrlKey`
ENTER: 13, //ALT: 18, // Check by `&& event.altKey`
ESC: 27, ENTER: "Enter",
TAB: 9, ESC: "Escape",
UPARROW: 38, TAB: "Tab",
UPARROW: "ArrowUp",
DOWNARROW: "ArrowDown",
LEFTARROW: "ArrowLeft",
RIGHTARROW: "ArrowRight",
"0": 48, "0": "0",
"1": 49, "1": "1",
"2": 50, "2": "2",
"3": 51, "3": "3",
"4": 52, "4": "4",
"5": 53, "5": "5",
"6": 54, "6": "6",
"7": 55, "7": "7",
"8": 56, "8": "8",
"9": 57, "9": "9",
A: 65, A: "a",
B: 66, B: "b",
C: 67, C: "c",
D: 68, D: "d",
E: 69, E: "e",
F: 70, F: "f",
G: 71, G: "g",
H: 72, H: "h",
I: 73, I: "i",
J: 74, J: "j",
K: 75, K: "k",
L: 76, L: "l",
M: 77, M: "m",
N: 78, N: "n",
O: 79, O: "o",
P: 80, P: "p",
Q: 81, Q: "q",
R: 82, R: "r",
S: 83, S: "s",
T: 84, T: "t",
U: 85, U: "u",
V: 86, V: "v",
W: 87, W: "w",
X: 88, X: "x",
Y: 89, Y: "y",
Z: 90, Z: "z",
}; };