mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-05-03 14:27:03 +02:00
fix infiltration keybinding
This commit is contained in:
@@ -1,22 +1,22 @@
|
||||
import React, { useEffect } from "react";
|
||||
|
||||
interface IProps {
|
||||
onKeyDown: (event: React.KeyboardEvent<HTMLElement>) => void;
|
||||
onKeyDown: (this: Document, event: KeyboardEvent) => void;
|
||||
onFailure: (options?: { automated: boolean }) => void;
|
||||
}
|
||||
|
||||
export function KeyHandler(props: IProps): React.ReactElement {
|
||||
let elem: any;
|
||||
useEffect(() => elem.focus());
|
||||
|
||||
function onKeyDown(event: React.KeyboardEvent<HTMLElement>): void {
|
||||
if (!event.isTrusted) {
|
||||
props.onFailure({ automated: true });
|
||||
return;
|
||||
useEffect(() => {
|
||||
console.log("binding");
|
||||
function press(this: Document, event: KeyboardEvent): void {
|
||||
console.log("press!");
|
||||
const f = props.onKeyDown.bind(this);
|
||||
f(event);
|
||||
}
|
||||
props.onKeyDown(event);
|
||||
}
|
||||
document.addEventListener("keydown", press);
|
||||
return () => document.removeEventListener("keydown", press);
|
||||
});
|
||||
|
||||
// invisible autofocused element that eats all the keypress for the minigames.
|
||||
return <div tabIndex={1} ref={(c) => (elem = c)} onKeyDown={onKeyDown} />;
|
||||
return <></>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user