mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
Runtime emits key pressed event
This commit is contained in:
parent
b7e40c9735
commit
508ac91b82
2 changed files with 10 additions and 7 deletions
|
@ -7,6 +7,15 @@ class Scratch3EventBlocks {
|
|||
* @type {Runtime}
|
||||
*/
|
||||
this.runtime = runtime;
|
||||
|
||||
this.runtime.on('KEY_PRESSED', key => {
|
||||
this.runtime.startHats('event_whenkeypressed', {
|
||||
KEY_OPTION: key
|
||||
});
|
||||
this.runtime.startHats('event_whenkeypressed', {
|
||||
KEY_OPTION: 'any'
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -116,17 +116,11 @@ class Keyboard {
|
|||
if (scratchKey === '') return;
|
||||
const index = this._keysPressed.indexOf(scratchKey);
|
||||
if (data.isDown) {
|
||||
this.runtime.emit('KEY_PRESSED', scratchKey);
|
||||
// If not already present, add to the list.
|
||||
if (index < 0) {
|
||||
this._keysPressed.push(scratchKey);
|
||||
}
|
||||
// Always trigger hats, even if it was already pressed.
|
||||
this.runtime.startHats('event_whenkeypressed', {
|
||||
KEY_OPTION: scratchKey
|
||||
});
|
||||
this.runtime.startHats('event_whenkeypressed', {
|
||||
KEY_OPTION: 'any'
|
||||
});
|
||||
} else if (index > -1) {
|
||||
// If already present, remove from the list.
|
||||
this._keysPressed.splice(index, 1);
|
||||
|
|
Loading…
Reference in a new issue