mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-16 14:28:36 +02:00
24 lines
786 B
TypeScript
24 lines
786 B
TypeScript
import React, { useEffect } from 'react';
|
|
|
|
interface IProps {
|
|
onKeyDown: (event: React.KeyboardEvent<HTMLElement>) => 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 {
|
|
console.log("isTrusted?", event.isTrusted)
|
|
if(!event.isTrusted) {
|
|
console.log("untrusted event!")
|
|
props.onFailure({ automated: true });
|
|
return;
|
|
}
|
|
props.onKeyDown(event);
|
|
}
|
|
|
|
// invisible autofocused element that eats all the keypress for the minigames.
|
|
return (<div tabIndex={1} ref={c => elem = c} onKeyDown={onKeyDown} />)
|
|
} |