From 39da0e91c2011966961071a1d3c138db32449dba Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Sat, 5 Jul 2025 18:03:24 +1200 Subject: Support touchscreen devices Click events on touchscreen devices are handled by the touchstart and touchend events. These events will now enable and disable the pointer device, move the pointer position, and press and release the primary pointer button. --- bedrock.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/bedrock.js b/bedrock.js index 7be6e4d..34ddc41 100644 --- a/bedrock.js +++ b/bedrock.js @@ -517,6 +517,17 @@ function EmulatorElement(options) { } } + emulator.touchStart = function(e) { + if (e.changedTouches.length) { + emulator.mouseMove(e.changedTouches[0]); } + br.dev.input.applyActive(true); + br.dev.input.applyButtons(0x01); + } + emulator.touchEnd = function(e) { + br.dev.input.applyActive(false); + br.dev.input.applyButtons(0x00); + } + fullscreenButton.addEventListener('click', emulator.toggleFullscreen); stateButton.addEventListener('click', emulator.toggleStatePanel); runButton.addEventListener('click', emulator.runProgram); @@ -528,6 +539,9 @@ function EmulatorElement(options) { canvas.addEventListener('pointermove', emulator.mouseMove); canvas.addEventListener('mousedown', emulator.mouseDown); canvas.addEventListener('mouseup', emulator.mouseUp); + canvas.addEventListener('touchstart', emulator.touchStart); + canvas.addEventListener('touchend', emulator.touchEnd); + canvas.addEventListener('touchcancel', emulator.touchEnd); canvas.addEventListener('mouseenter', emulator.mouseEnter); canvas.addEventListener('mouseleave', emulator.mouseExit); canvas.addEventListener('wheel', emulator.mouseScroll); -- cgit v1.2.3-70-g09d2