mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-25 07:22:33 -05:00
be83c0ee74
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.
28 lines
663 B
JavaScript
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;
|