fix infiltration keybinding

This commit is contained in:
Olivier Gagnon
2021-09-24 22:15:19 -04:00
parent 76e6cb4ecc
commit 65cb519801
10 changed files with 21 additions and 21 deletions
+11 -11
View File
@@ -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 <></>;
}