Discuss Scratch

BookOwl
Scratcher
1000+ posts

A "last key pressed" reporter (9:3:2) Now with a Q&A!

I believe that a
last key pressed ::sensing reporter
block would be very useful. As the name says, it would report the last key pressed.
This could be used for lots of projects, such as projects that don't want to use a
ask [] and wait
or for projects that want to do something if a key is pressed. For example, you could do
say [Press "y" if you want to continue, any other key to exit]
wait until <key [any v] pressed?>
if <(last key pressed ::sensing reporter) = [y]> then
do something ::custom
end
A workaround for this specific case is:
set [key v] to [none]
say [Press "y" if you want to continue, any other key to exit]
repeat until <not <(key) = [none]>>
if <key [y v] pressed?> then
set [key v] to [y]
else
if <key [any v] pressed?> then
set [key v] to [other]
end
end
end
if <(key) = [other]> then
stop [this script v] // exit
end
... // continue
(Thanks to Znapi for the workaround.)

The general workaround for this block is not too hard, but it is long and repetitive and involves 28 if-else blocks.

Q & A
Q: What would this block do if an arrow key was pressed?
A: It would ignore it. If the ‘p’ key was pressed, and then the left arrow key was pressed, this block would return ‘p’

Q: How would this block respond to non-english characters?
A: It would just return that character! (I really don't know why this is such a big deal.)

Q: How would this deal with the space key?
A: It would either return the string “space” or the space character.

Supporters:
BookOwl
ChocolatePi
stickfiregames
TheMonsterOfTheDeep
Nether_before
Jonathan50
Prinseskat
A-no-meep
Junk_Collector

Semi-Supporters:
DaSpudLord
Cub56
Znapi

No Supporters:
Blank1234
scratchinghead

Please tell me what you think of this idea.

Last edited by BookOwl (Sept. 25, 2015 23:39:59)

DaSpudLord
Scratcher
1000+ posts

A "last key pressed" reporter (9:3:2) Now with a Q&A!

Semi-support because of workaround, and also, how would it deal with named keys, like space and arrow keys?
BookOwl
Scratcher
1000+ posts

A "last key pressed" reporter (9:3:2) Now with a Q&A!

DaSpudLord wrote:

Semi-support because of workaround, and also, how would it deal with named keys, like space and arrow keys?
Do you REALLY want to make a script that has 31 if blocks? Really?
It would return the name of the key. The space key would return space, and the up arrow key would return up arrow.
DaSpudLord
Scratcher
1000+ posts

A "last key pressed" reporter (9:3:2) Now with a Q&A!

BookOwl wrote:

DaSpudLord wrote:

Semi-support because of workaround, and also, how would it deal with named keys, like space and arrow keys?
Do you REALLY want to make a script that has 31 if blocks? Really?
It would return the name of the key. The space key would return space, and the up arrow key would return up arrow.
What about for other languages, like Spanish, French, or Chinese?
gdpr533f604550b2f20900645890
Scratcher
1000+ posts

A "last key pressed" reporter (9:3:2) Now with a Q&A!

Blank1234
Scratcher
500+ posts

A "last key pressed" reporter (9:3:2) Now with a Q&A!

workaroundable, no support
gdpr533f604550b2f20900645890
Scratcher
1000+ posts

A "last key pressed" reporter (9:3:2) Now with a Q&A!

Blank1234 wrote:

workaroundable, no support
The workaround is tedious, which is the reason for the block.
Paddle2See
Scratch Team
1000+ posts

A "last key pressed" reporter (9:3:2) Now with a Q&A!

Chibi-Matoran wrote:

Duplicate
Thanks for the link! It does look like this is a duplicate topic so I'll close it to keep the conversation all in one place.

Please use the existing topic in the link above.
ChocolatePi
Scratcher
1000+ posts

A "last key pressed" reporter (9:3:2) Now with a Q&A!

DaSpudLord wrote:

BookOwl wrote:

DaSpudLord wrote:

Semi-support because of workaround, and also, how would it deal with named keys, like space and arrow keys?
Do you REALLY want to make a script that has 31 if blocks? Really?
It would return the name of the key. The space key would return space, and the up arrow key would return up arrow.
What about for other languages, like Spanish, French, or Chinese?
The Chinese have Pinyin keyboards, which is just letters with accents and the umlaut. They don't actually type in the characters xD
Obviously, it would just return the last key pressed. Simple.
CatsUnited
Scratcher
1000+ posts

A "last key pressed" reporter (9:3:2) Now with a Q&A!

Isn't this supposed to be closed?
ChocolatePi
Scratcher
1000+ posts

A "last key pressed" reporter (9:3:2) Now with a Q&A!

Paddle2See wrote:

Chibi-Matoran wrote:

Duplicate
Thanks for the link! It does look like this is a duplicate topic so I'll close it to keep the conversation all in one place.

Please use the existing topic in the link above.
Wait wait wait, that's not a duplicate! That's a (keys pressed) topic, not a (last key pressed) topic!
gdpr533f604550b2f20900645890
Scratcher
1000+ posts

A "last key pressed" reporter (9:3:2) Now with a Q&A!

CatsUnited wrote:

Isn't this supposed to be closed?
Paddle2See probably forgot.
DaSpudLord
Scratcher
1000+ posts

A "last key pressed" reporter (9:3:2) Now with a Q&A!

ChocolatePi wrote:

DaSpudLord wrote:

BookOwl wrote:

DaSpudLord wrote:

Semi-support because of workaround, and also, how would it deal with named keys, like space and arrow keys?
Do you REALLY want to make a script that has 31 if blocks? Really?
It would return the name of the key. The space key would return space, and the up arrow key would return up arrow.
What about for other languages, like Spanish, French, or Chinese?
The Chinese have Pinyin keyboards, which is just letters with accents and the umlaut. They don't actually type in the characters xD
Obviously, it would just return the last key pressed. Simple.
That's not what I was talking about. The spacebar and arrow keys probably have other names in other languages. How would those be reported?
ChocolatePi
Scratcher
1000+ posts

A "last key pressed" reporter (9:3:2) Now with a Q&A!

DaSpudLord wrote:

ChocolatePi wrote:

DaSpudLord wrote:

BookOwl wrote:

DaSpudLord wrote:

Semi-support because of workaround, and also, how would it deal with named keys, like space and arrow keys?
Do you REALLY want to make a script that has 31 if blocks? Really?
It would return the name of the key. The space key would return space, and the up arrow key would return up arrow.
What about for other languages, like Spanish, French, or Chinese?
The Chinese have Pinyin keyboards, which is just letters with accents and the umlaut. They don't actually type in the characters xD
Obviously, it would just return the last key pressed. Simple.
That's not what I was talking about. The spacebar and arrow keys probably have other names in other languages. How would those be reported?
I don't know. Maybe a space key symbol? It's up to the ST. Honestly sometimes I think you're just looking for reasons to not support suggestions. I think this is a good idea.
DaSpudLord
Scratcher
1000+ posts

A "last key pressed" reporter (9:3:2) Now with a Q&A!

ChocolatePi wrote:

DaSpudLord wrote:

ChocolatePi wrote:

DaSpudLord wrote:

BookOwl wrote:

DaSpudLord wrote:

Semi-support because of workaround, and also, how would it deal with named keys, like space and arrow keys?
Do you REALLY want to make a script that has 31 if blocks? Really?
It would return the name of the key. The space key would return space, and the up arrow key would return up arrow.
What about for other languages, like Spanish, French, or Chinese?
The Chinese have Pinyin keyboards, which is just letters with accents and the umlaut. They don't actually type in the characters xD
Obviously, it would just return the last key pressed. Simple.
That's not what I was talking about. The spacebar and arrow keys probably have other names in other languages. How would those be reported?
I don't know. Maybe a space key symbol? It's up to the ST. Honestly sometimes I think you're just looking for reasons to not support suggestions. I think this is a good idea.
Space key symbol? What would that look like? And how would one type that into a textbox? And I don't no support suggestions just for the sake of arguing or no supporting- I try to use logical reasons to determine my stance. And I'm not completely no supporting- I'm semi supporting.
Paddle2See
Scratch Team
1000+ posts

A "last key pressed" reporter (9:3:2) Now with a Q&A!

ChocolatePi wrote:

Paddle2See wrote:

Chibi-Matoran wrote:

Duplicate
Thanks for the link! It does look like this is a duplicate topic so I'll close it to keep the conversation all in one place.

Please use the existing topic in the link above.
Wait wait wait, that's not a duplicate! That's a (keys pressed) topic, not a (last key pressed) topic!
Good point - also made by the topic owner!

Okay, let's leave it re-open and see if we can develop the idea any further
stickfiregames
Scratcher
1000+ posts

A "last key pressed" reporter (9:3:2) Now with a Q&A!

DaSpudLord wrote:

ChocolatePi wrote:

DaSpudLord wrote:

ChocolatePi wrote:

DaSpudLord wrote:

BookOwl wrote:

DaSpudLord wrote:

Semi-support because of workaround, and also, how would it deal with named keys, like space and arrow keys?
Do you REALLY want to make a script that has 31 if blocks? Really?
It would return the name of the key. The space key would return space, and the up arrow key would return up arrow.
What about for other languages, like Spanish, French, or Chinese?
The Chinese have Pinyin keyboards, which is just letters with accents and the umlaut. They don't actually type in the characters xD
Obviously, it would just return the last key pressed. Simple.
That's not what I was talking about. The spacebar and arrow keys probably have other names in other languages. How would those be reported?
I don't know. Maybe a space key symbol? It's up to the ST. Honestly sometimes I think you're just looking for reasons to not support suggestions. I think this is a good idea.
Space key symbol? What would that look like? And how would one type that into a textbox? And I don't no support suggestions just for the sake of arguing or no supporting- I try to use logical reasons to determine my stance. And I'm not completely no supporting- I'm semi supporting.
“space key symbol” is just a space. There are also arrow characters ↑↓←→ but they can't be typed normally, I still support it though.

Last edited by stickfiregames (Sept. 17, 2015 21:07:03)

BookOwl
Scratcher
1000+ posts

A "last key pressed" reporter (9:3:2) Now with a Q&A!

Sorry that I haven't responded - I have been very busy.
In the
<key [ v] pressed?>
and
when [ v] key pressed
blocks, when you want to check for the space key, you use “space”, and for arrow keys, you use “<direction> arrow”, where <direction> is any of up/down/left/right. I think that this block should emulate those, and return “space” when the space key is pressed, and “left arrow” when the left arrow key is pressed. Or the arrow keys could just not report, since they are not characters. Either way is fine with me.
BookOwl
Scratcher
1000+ posts

A "last key pressed" reporter (9:3:2) Now with a Q&A!

Scratcher1002 wrote:

BookOwl wrote:

DaSpudLord wrote:

Semi-support because of workaround, and also, how would it deal with named keys, like space and arrow keys?
Do you REALLY want to make a script that has 31 if blocks? Really?
It would return the name of the key. The space key would return space, and the up arrow key would return up arrow.
Sorry, I mis-understood you.
Do this then:
<very very very long script removed by BookOwl>
Yes I know, VERY tedious. And in the blank write whatever key was pressed into a variable. Not THAT hard.
So, do you support or not?
TheMonsterOfTheDeep
Scratcher
1000+ posts

A "last key pressed" reporter (9:3:2) Now with a Q&A!

The reason I don't like the workaround is because you lose out in performance either way:
  • With the giant stack of if blocks, the editor lags
  • With a loop, key detection lags
Both of these are annoying but it's probably better to go with the first one because at least then your project works to some extent.

Support.

Powered by DjangoBB