refactor(client): ♻️ update keyboard event handler to fit new API

This commit is contained in:
Julien Oculi 2024-06-25 13:31:27 +02:00
parent a585177a3f
commit 4ccf981f12

View file

@ -78,11 +78,22 @@
) )
// Keyboard handler // Keyboard handler
document.addEventListener('keydown', (event) => { document.addEventListener('keydown', ({ code }) => {
const key = event.keyCode if (code === 'ArrowUp') {
const { command, value } = keyMap[key] return sendCommand(getEndpoint(), 'forward', 2)
const endpoint = getEndpoint() }
sendCommand(endpoint, command, value) if (code === 'ArrowDown') {
return sendCommand(getEndpoint(), 'backward', 2)
}
if (code === 'ArrowLeft') {
return sendCommand(getEndpoint(), 'left', 5)
}
if (code === 'ArrowRight') {
return sendCommand(getEndpoint(), 'right', 5)
}
if (code === 'Space') {
return sendCommand(getEndpoint(), 'stop', 0)
}
}) })
// Settings handler // Settings handler
@ -197,18 +208,5 @@
} }
return sendCommand(endpoint, positiveCommand, value) return sendCommand(endpoint, positiveCommand, value)
} }
function storeInput() {
ipInput = document.getElementById('ip').value
valueRot = document.getElementById('valueRot').value
valueLength = document.getElementById('valueLength').value
keyMap = {
38: { command: 'forward', value: valueLength },
40: { command: 'backward', value: valueLength },
37: { command: 'left', value: valueRot },
39: { command: 'right', value: valueRot },
32: { command: 'stop', value: 0 },
}
}
</script> </script>
</html> </html>