summaryrefslogtreecommitdiff
path: root/objects.js
diff options
context:
space:
mode:
authorGubolin <gubolin@fantasymail.de>2014-11-03 16:57:06 +0100
committerGubolin <gubolin@fantasymail.de>2014-11-03 16:57:06 +0100
commit5b9385d4644a11374b3c7899f9f6e2092ca92c2f (patch)
tree2d1bb905f36f59f1c5c00ddd2510dc9182f4fff0 /objects.js
parentcb4302b455a0ace2d79bd3090f32d913e8ac6612 (diff)
downloadsnap-5b9385d4644a11374b3c7899f9f6e2092ca92c2f.tar.gz
snap-5b9385d4644a11374b3c7899f9f6e2092ca92c2f.zip
add global LAST KEY PRESSED variable
Diffstat (limited to 'objects.js')
-rw-r--r--objects.js29
1 files changed, 28 insertions, 1 deletions
diff --git a/objects.js b/objects.js
index 2263883..d0d48e3 100644
--- a/objects.js
+++ b/objects.js
@@ -581,6 +581,11 @@ SpriteMorph.prototype.initBlocks = function () {
category: 'control',
spec: 'when %keyHat key pressed'
},
+ getLastKey: {
+ type: 'reporter',
+ category: 'control',
+ spec: 'last key pressed'
+ },
receiveClick: {
type: 'hat',
category: 'control',
@@ -1801,6 +1806,8 @@ SpriteMorph.prototype.blockTemplates = function (category) {
blocks.push(block('receiveGo'));
blocks.push(block('receiveKey'));
+ blocks.push(watcherToggle('getLastKey'));
+ blocks.push(block('getLastKey'));
blocks.push(block('receiveClick'));
blocks.push(block('receiveMessage'));
blocks.push('-');
@@ -3539,6 +3546,16 @@ SpriteMorph.prototype.getTempo = function () {
return 0;
};
+// SpriteMorph last key
+
+SpriteMorph.prototype.getLastKey = function () {
+ var stage = this.parentThatIsA(StageMorph);
+ if (stage) {
+ return stage.getLastKey();
+ }
+ return '';
+};
+
// SpriteMorph last message
SpriteMorph.prototype.getLastMessage = function () {
@@ -4259,6 +4276,7 @@ StageMorph.prototype.init = function (globals) {
this.timerStart = Date.now();
this.tempo = 60; // bpm
+ this.lastKey = '';
this.lastMessage = '';
this.watcherUpdateFrequency = 2;
@@ -4539,6 +4557,12 @@ StageMorph.prototype.getTempo = function () {
return +this.tempo;
};
+// StageMorph keys
+
+StageMorph.prototype.getLastKey = function () {
+ return this.lastKey || '';
+};
+
// StageMorph messages
StageMorph.prototype.getLastMessage = function () {
@@ -4733,6 +4757,7 @@ StageMorph.prototype.fireKeyEvent = function (key) {
if (evt === 'esc') {
return this.fireStopAllEvent();
}
+ this.lastKey = evt;
this.children.concat(this).forEach(function (morph) {
if (morph instanceof SpriteMorph || morph instanceof StageMorph) {
hats = hats.concat(morph.allHatBlocksForKey(evt));
@@ -4951,6 +4976,8 @@ StageMorph.prototype.blockTemplates = function (category) {
blocks.push(block('receiveGo'));
blocks.push(block('receiveKey'));
+ blocks.push(watcherToggle('getLastKey'));
+ blocks.push(block('getLastKey'));
blocks.push(block('receiveClick'));
blocks.push(block('receiveMessage'));
blocks.push('-');
@@ -6742,7 +6769,7 @@ WatcherMorph.prototype.object = function () {
WatcherMorph.prototype.isGlobal = function (selector) {
return contains(
- ['getLastAnswer', 'getLastMessage', 'getTempo', 'getTimer',
+ ['getLastAnswer', 'getLastKey', 'getLastMessage', 'getTempo', 'getTimer',
'reportMouseX', 'reportMouseY'],
selector
);