From a152f2a20096dd0b35c6a8cf8933db41ce1f9abe Mon Sep 17 00:00:00 2001 From: Nick Mowen Date: Tue, 27 Dec 2022 10:48:17 -0700 Subject: [PATCH] Add ability to control camera with keyboard shortcuts --- web/src/components/CameraControlPanel.jsx | 59 +++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/web/src/components/CameraControlPanel.jsx b/web/src/components/CameraControlPanel.jsx index 820e618d1..803902ae3 100644 --- a/web/src/components/CameraControlPanel.jsx +++ b/web/src/components/CameraControlPanel.jsx @@ -48,6 +48,65 @@ export default function CameraControlPanel({ camera = '' }) { return ; } + document.addEventListener('keydown', (e) => { + if (!e) { + return; + } + + if (e.repeat) { + e.preventDefault(); + return; + } + + console.log('Handling key down ' + e.key); + + if (ptz.features.includes('pt')) { + if (e.key === 'ArrowLeft') { + e.preventDefault(); + onSetMove(e, 'LEFT'); + } else if (e.key === 'ArrowRight') { + e.preventDefault(); + onSetMove(e, 'RIGHT'); + } else if (e.key === 'ArrowUp') { + e.preventDefault(); + onSetMove(e, 'UP'); + } else if (e.key === 'ArrowDown') { + e.preventDefault(); + onSetMove(e, 'DOWN'); + } + + if (ptz.features.includes('zoom')) { + if (e.key == '+') { + e.preventDefault(); + onSetZoom(e, 'IN'); + } else if (e.key == '-') { + e.preventDefault(); + onSetZoom(e, 'OUT'); + } + } + } + }); + + document.addEventListener('keyup', (e) => { + if (!e || e.repeat) { + return; + } + + console.log('Handling key up ' + e.key); + + if ( + e.key === 'ArrowLeft' || + e.key === 'ArrowRight' || + e.key === 'ArrowUp' || + e.key === 'ArrowDown' || + e.key === '+' || + e.key === '-' + ) { + e.preventDefault(); + onSetStop(e); + } + }); + return (
{ptz.features.includes('pt') && (