mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-08-28 22:30:40 -04:00
Key repeats, with OS delay (#168)
This commit is contained in:
parent
91cdec1547
commit
c357a62005
1 changed files with 11 additions and 13 deletions
|
@ -44,10 +44,10 @@ Keyboard.prototype._keyCodeToScratchKey = function (keyCode) {
|
||||||
}
|
}
|
||||||
switch (keyCode) {
|
switch (keyCode) {
|
||||||
case 32: return 'space';
|
case 32: return 'space';
|
||||||
case 37: return 'leftarrow';
|
case 37: return 'left arrow';
|
||||||
case 38: return 'uparrow';
|
case 38: return 'up arrow';
|
||||||
case 39: return 'rightarrow';
|
case 39: return 'right arrow';
|
||||||
case 40: return 'downarrow';
|
case 40: return 'down arrow';
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
@ -59,16 +59,14 @@ Keyboard.prototype.postData = function (data) {
|
||||||
// If not already present, add to the list.
|
// If not already present, add to the list.
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
this._keysPressed.push(data.keyCode);
|
this._keysPressed.push(data.keyCode);
|
||||||
this.runtime.startHats('event_whenkeypressed',
|
|
||||||
{
|
|
||||||
'KEY_OPTION': this._keyCodeToScratchKey(data.keyCode)
|
|
||||||
});
|
|
||||||
|
|
||||||
this.runtime.startHats('event_whenkeypressed',
|
|
||||||
{
|
|
||||||
'KEY_OPTION': 'any'
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
// Always trigger hats, even if it was already pressed.
|
||||||
|
this.runtime.startHats('event_whenkeypressed', {
|
||||||
|
'KEY_OPTION': this._keyCodeToScratchKey(data.keyCode)
|
||||||
|
});
|
||||||
|
this.runtime.startHats('event_whenkeypressed', {
|
||||||
|
'KEY_OPTION': 'any'
|
||||||
|
});
|
||||||
} else if (index > -1) {
|
} else if (index > -1) {
|
||||||
// If already present, remove from the list.
|
// If already present, remove from the list.
|
||||||
this._keysPressed.splice(index, 1);
|
this._keysPressed.splice(index, 1);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue