mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-10-23 10:13:13 +02:00
22 lines
654 B
TypeScript
22 lines
654 B
TypeScript
import React, { useEffect } from "react";
|
|
|
|
interface IProps {
|
|
onKeyDown: (this: Document, event: KeyboardEvent) => void;
|
|
onFailure: (options?: { automated: boolean }) => void;
|
|
}
|
|
|
|
export function KeyHandler(props: IProps): React.ReactElement {
|
|
useEffect(() => {
|
|
function press(this: Document, event: KeyboardEvent): void {
|
|
if (!event.isTrusted) return;
|
|
const f = props.onKeyDown.bind(this);
|
|
f(event);
|
|
}
|
|
document.addEventListener("keydown", press);
|
|
return () => document.removeEventListener("keydown", press);
|
|
});
|
|
|
|
// invisible autofocused element that eats all the keypress for the minigames.
|
|
return <></>;
|
|
}
|