M src/device.js => src/device.js +16 -11
@@ 39,23 39,28 @@ function initDevices () {
}
requestAnimationFrame(frame)
const input = document.getElementById('input')
+ const sendButton = document.getElementById('send-button')
input.focus()
const output = document.getElementById('output')
+ function sendInput () {
+ try {
+ value = JSON.parse(input.value)
+ } catch {
+ value = input.value
+ }
+ logOutput(`> ${JSON.stringify(value)}`)
+ processEvent([
+ 'input',
+ value
+ ])
+ input.value = ''
+ }
input.addEventListener('keypress', e => {
if (e.key === 'Enter') {
- try {
- value = JSON.parse(input.value)
- } catch {
- value = input.value
- }
- logOutput(`> ${JSON.stringify(value)}`)
- processEvent([
- 'input',
- value
- ])
- input.value = ''
+ sendInput()
}
})
+ sendButton.addEventListener('click', sendInput)
ctx = canvas.getContext("2d")
processEvent(['init', null])
}
M src/index.html => src/index.html +1 -1
@@ 13,7 13,7 @@
<canvas id="canvas" width="500" height="500">
</canvas>
</div>
- <input id="input" />
+ <input id="input" /><input value="send" type="button" id="send-button" />
<div style="white-space: pre;" id="output"></div>
</body>
</html>