scratch-vm/src/io/mouseWheel.js
Florrie be83c0ee74 Mouse wheel IO system
Towards fixing #865. This adds an IO class for detecting the mouse wheel
being scrolled. Basic tests are included; they mock the runtime to see
what blocks are activated by scrolling.
2018-01-26 17:13:01 -04:00

28 lines
663 B
JavaScript

class MouseWheel {
constructor (runtime) {
/**
* Reference to the owning Runtime.
* @type{!Runtime}
*/
this.runtime = runtime;
}
/**
* Mouse wheel DOM event handler.
* @param {object} data Data from DOM event.
*/
postData (data) {
const matchFields = {};
if (data.deltaY < 0) {
matchFields.KEY_OPTION = 'up arrow';
} else if (data.deltaY > 0) {
matchFields.KEY_OPTION = 'down arrow';
} else {
return;
}
this.runtime.startHats('event_whenkeypressed', matchFields);
}
}
module.exports = MouseWheel;