Loading files
"use client";
import { useEffect } from "react";
type Handlers = {
onIndex: (i: number) => void; // keys 1-4 -> index 0-3
};
function isTypingTarget(el: EventTarget | null): boolean {
const t = el as HTMLElement | null;
if (!t) return false;
const tag = t.tagName;
return (
tag === "INPUT" ||
tag === "TEXTAREA" ||
tag === "SELECT" ||
t.isContentEditable
);
}
/**
* Global camera hotkeys: 1-4 select a feed directly (same as /control). Arrow / bracket keys are
* intentionally NOT bound here — they drive the arm (arrows = jog, ' . = Z, [ ] = gripper) via the
* teleop. Cameras are otherwise switched with the on-screen ◀ ▶ buttons. Bails while typing,
* composing (IME), or holding a modifier. Pass a memoized callback.
*/
export function useDirectorKeys({ onIndex }: Handlers) {
useEffect(() => {
const onKey = (e: KeyboardEvent) => {
if (e.defaultPrevented || e.metaKey || e.ctrlKey || e.altKey) return;
if (e.isComposing) return;
if (isTypingTarget(document.activeElement) || isTypingTarget(e.target)) return;
if (e.key >= "1" && e.key <= "4") {
e.preventDefault();
onIndex(Number(e.key) - 1);
}
};
window.addEventListener("keydown", onKey);
return () => window.removeEventListener("keydown", onKey);
}, [onIndex]);
}
05241c15dThis file is pinned to the selected release. Download the original to open it in your design tool.