Microsoft Surface Haptics Buzz Continuous waveform Integration
by pedro_g_s
HTML
<html>
<body>
<canvas id="c" width="1280" height="720" style="background: blue"></canvas>
<script>
const canvas = document.querySelector('#c');
// Start a continuous pre-defined waveform on pointerdown
canvas.addEventListener('pointerdown', function(e) {
console.log("Pointer down detected")
if (e.haptics) {
const WAVEFORM_BUZZ_CONTINUOUS = 0x1004;
const waveform = new HapticsPredefinedWaveform({
waveformId: WAVEFORM_BUZZ_CONTINUOUS
});
console.log("Starting haptics buzz waveform")
e.haptics.play(waveform);
}
});
// Stop the waveform on pointerup
canvas.addEventListener('pointerup', function(e) {
console.log("Pointer up detected")
if (e.haptics) {
console.log("Stopping haptics API")
e.haptics.stop();
}
});
</script>
</body>
</html>