refactor(client): ♻️ update keyboard event handler to fit new API
This commit is contained in:
parent
a585177a3f
commit
4ccf981f12
|
@ -78,11 +78,22 @@
|
|||
)
|
||||
|
||||
// Keyboard handler
|
||||
document.addEventListener('keydown', (event) => {
|
||||
const key = event.keyCode
|
||||
const { command, value } = keyMap[key]
|
||||
const endpoint = getEndpoint()
|
||||
sendCommand(endpoint, command, value)
|
||||
document.addEventListener('keydown', ({ code }) => {
|
||||
if (code === 'ArrowUp') {
|
||||
return sendCommand(getEndpoint(), 'forward', 2)
|
||||
}
|
||||
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
|
||||
|
@ -197,18 +208,5 @@
|
|||
}
|
||||
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>
|
||||
</html>
|
||||
|
|
Loading…
Reference in a new issue