bitburner-src/src/Infiltration/ui/KeyHandler.tsx

21 lines
618 B
TypeScript
Raw Normal View History

2021-09-05 01:09:30 +02:00
import React, { useEffect } from "react";
interface IProps {
2021-09-25 04:15:19 +02:00
onKeyDown: (this: Document, event: KeyboardEvent) => void;
2021-09-05 01:09:30 +02:00
onFailure: (options?: { automated: boolean }) => void;
}
export function KeyHandler(props: IProps): React.ReactElement {
2021-09-25 04:15:19 +02:00
useEffect(() => {
function press(this: Document, event: KeyboardEvent): void {
const f = props.onKeyDown.bind(this);
f(event);
2021-08-15 21:23:39 +02:00
}
2021-09-25 04:15:19 +02:00
document.addEventListener("keydown", press);
return () => document.removeEventListener("keydown", press);
});
2021-08-15 21:23:39 +02:00
2021-09-05 01:09:30 +02:00
// invisible autofocused element that eats all the keypress for the minigames.
2021-09-25 04:15:19 +02:00
return <></>;
2021-09-05 01:09:30 +02:00
}