This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-03-08 17:28:34

shadow_7283
Scratcher
Registered: 2007-11-07
Posts: 1000+

Can anyone make a (key pressed) block?

A squeak hack for (key pressed) would help so many users in their type-based projects. I requested one from nxIII, but it didn't quite work.

If any other advanced squeak hackers can help me out here, it would be greatly appreciated. Thanks!  big_smile

Offline

 

#2 2010-03-08 17:58:39

cds56
Scratcher
Registered: 2008-05-02
Posts: 500+

Re: Can anyone make a (key pressed) block?

There is a key-pressed block already.... It's my favorite one.


http://img192.imageshack.us/img192/909/meowdevlogo.pnghttp://i32.tinypic.com/pucti.png

Offline

 

#3 2010-03-08 18:07:40

Jonathanpb
Scratcher
Registered: 2008-07-25
Posts: 1000+

Re: Can anyone make a (key pressed) block?

He's not talking about <key [space] pressed>; he's talking about <key pressed>.


"Human beings... must have action; and they will make it if they cannot find it.
-Charlotte Brontë

Offline

 

#4 2010-03-08 18:19:57

shadow_7283
Scratcher
Registered: 2007-11-07
Posts: 1000+

Re: Can anyone make a (key pressed) block?

What JonathanPB said, but like a variable (key pressed --> ) <--

Offline

 

#5 2010-03-08 18:21:36

technoguyx
Scratcher
Registered: 2008-10-18
Posts: 1000+

Re: Can anyone make a (key pressed) block?

For less confusion name it "any key pressed".


http://getgnulinux.org/links/en/linuxliberated_4_78x116.png

Offline

 

#6 2010-03-08 21:56:41

billyedward
Scratcher
Registered: 2008-01-03
Posts: 500+

Re: Can anyone make a (key pressed) block?

I've worked this into streak...
However, in the mean time you can do thia uaing BYOB - just make the block a boolean reporter, and have it report a loooooooonnnnnnnggggg boolean expression which evaluates whether any key is pressed using many many nested OR blocks.


"I'd love to change the world, but they haven't released the source code yet."
Check out the latest version of Streak --> http://billy.scienceontheweb.net/Streak

Offline

 

#7 2010-03-08 22:23:39

shadow_7283
Scratcher
Registered: 2007-11-07
Posts: 1000+

Re: Can anyone make a (key pressed) block?

billyedward wrote:

I've worked this into streak...
However, in the mean time you can do thia uaing BYOB - just make the block a boolean reporter, and have it report a loooooooonnnnnnnggggg boolean expression which evaluates whether any key is pressed using many many nested OR blocks.

That's a good idea, but I would like to be able to upload any projects that might include this to the Scratch website. Also, it is meant to read WHAT key is being pressed. For
example, if you pressed the space key and had a script that said
set variable to (key pressed), the variable would read
"space". Thanks though.

Offline

 

#8 2010-03-09 11:11:09

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Can anyone make a (key pressed) block?

shadow_7283 wrote:

billyedward wrote:

I've worked this into streak...
However, in the mean time you can do thia uaing BYOB - just make the block a boolean reporter, and have it report a loooooooonnnnnnnggggg boolean expression which evaluates whether any key is pressed using many many nested OR blocks.

That's a good idea, but I would like to be able to upload any projects that might include this to the Scratch website. Also, it is meant to read WHAT key is being pressed. For
example, if you pressed the space key and had a script that said
set variable to (key pressed), the variable would read
"space". Thanks though.

That complicates things... you could probably still do that in BYOB, just have an internal variable whichs sets to it, ill give it a go.


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#9 2010-03-09 11:58:43

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Can anyone make a (key pressed) block?

There you go! Made it in BYOB though.


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#10 2010-03-09 13:47:45

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Can anyone make a (key pressed) block?

Mine should have worked, bu it didn't...


nXIII

Offline

 

#11 2010-03-09 13:49:41

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Can anyone make a (key pressed) block?

nXIII wrote:

Mine should have worked, bu it didn't...

How did you make it? Did you try to do it in the browser part?


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#12 2010-03-17 23:40:49

shadow_7283
Scratcher
Registered: 2007-11-07
Posts: 1000+

Re: Can anyone make a (key pressed) block?

Bump

Offline

 

#13 2010-03-18 12:21:53

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Can anyone make a (key pressed) block?

shadow_7283 wrote:

Bump

Try that http://www.mediafire.com/?0zz4l3yggvj


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#14 2010-03-18 12:30:30

shadow_7283
Scratcher
Registered: 2007-11-07
Posts: 1000+

Re: Can anyone make a (key pressed) block?

markyparky56 wrote:

shadow_7283 wrote:

Bump

Try that http://www.mediafire.com/?0zz4l3yggvj

It's really great, I just wish we could put it into Scratch....

Offline

 

#15 2010-03-18 13:21:08

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Can anyone make a (key pressed) block?

shadow_7283 wrote:

markyparky56 wrote:

shadow_7283 wrote:

Bump

Try that http://www.mediafire.com/?0zz4l3yggvj

It's really great, I just wish we could put it into Scratch....

Yeah...


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#16 2010-03-18 14:32:12

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Can anyone make a (key pressed) block?

Wouldn't this work?

[blocks]
<when green flag clicked>
<set{ Key Pressed   }to( None

<when[ Space  ]key pressed>
<set{ Key Pressed   }to( Space
<wait until><<  <not> <key[ Space  ]pressed?>  >>
<set{ Key Pressed   }to( None

<when[ A ]key pressed>
<set{ Key Pressed   }to( A
<wait until><<  <not> <key[ A ]pressed?>  >>
<set{ Key Pressed   }to( None

... Make a whole lot more scripts like this for different keys ...

<when[ Z ]key pressed>
<set{ Key Pressed   }to( Z
<wait until><<  <not> <key[ Z ]pressed?>  >>
<set{ Key Pressed   }to( None

[/blocks]
It will only work for one key at a time...but maybe that is sufficient for what you want?


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#17 2010-03-18 15:55:30

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Can anyone make a (key pressed) block?

Paddle2See wrote:

Wouldn't this work?

[blocks]
<when green flag clicked>
<set{ Key Pressed   }to( None

<when[ Space  ]key pressed>
<set{ Key Pressed   }to( Space
<wait until><<  <not> <key[ Space  ]pressed?>  >>
<set{ Key Pressed   }to( None

<when[ A ]key pressed>
<set{ Key Pressed   }to( A
<wait until><<  <not> <key[ A ]pressed?>  >>
<set{ Key Pressed   }to( None

... Make a whole lot more scripts like this for different keys ...

<when[ Z ]key pressed>
<set{ Key Pressed   }to( Z
<wait until><<  <not> <key[ Z ]pressed?>  >>
<set{ Key Pressed   }to( None

[/blocks]
It will only work for one key at a time...but maybe that is sufficient for what you want?

Thats kind of what i did, but i bundled it all into one block using Byob.


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#18 2010-03-18 16:26:14

shadow_7283
Scratcher
Registered: 2007-11-07
Posts: 1000+

Re: Can anyone make a (key pressed) block?

Paddle2See wrote:

Wouldn't this work?

[blocks]
<when green flag clicked>
<set{ Key Pressed   }to( None

<when[ Space  ]key pressed>
<set{ Key Pressed   }to( Space
<wait until><<  <not> <key[ Space  ]pressed?>  >>
<set{ Key Pressed   }to( None

<when[ A ]key pressed>
<set{ Key Pressed   }to( A
<wait until><<  <not> <key[ A ]pressed?>  >>
<set{ Key Pressed   }to( None

... Make a whole lot more scripts like this for different keys ...

<when[ Z ]key pressed>
<set{ Key Pressed   }to( Z
<wait until><<  <not> <key[ Z ]pressed?>  >>
<set{ Key Pressed   }to( None

[/blocks]
It will only work for one key at a time...but maybe that is sufficient for what you want?

It's a great method, but the only reason I went to the trouble of posting a topic asking for a hack is to avoid all these scripts. Using it you could shorten 52 scripts to 1. Thanks though!

Offline

 

#19 2010-04-02 05:45:01

Chrischb
Scratcher
Registered: 2008-07-24
Posts: 1000+

Re: Can anyone make a (key pressed) block?

That senses clicking...  hmm


I fall: It's a tragedy. You fall: It's comedy.
Hmph enjoy your fall - I get a lovely spring... without pans of new leaves.

Offline

 

#20 2010-04-02 11:10:55

shadow_7283
Scratcher
Registered: 2007-11-07
Posts: 1000+

Re: Can anyone make a (key pressed) block?

Chrischb wrote:

That senses clicking...  hmm

HUH?

Offline

 

#21 2010-04-02 16:48:05

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Can anyone make a (key pressed) block?

If you want, just make a new method that is this

Code:

(Sensor keyPressed: (self asciiFor: 'a')) ifTrue: [^ 'a'].
(Sensor keyPressed: (self asciiFor: 'b')) ifTrue: [^ 'b'].
...

type thing.


nXIII

Offline

 

#22 2010-04-03 00:58:35

scoreman
Scratcher
Registered: 2009-10-03
Posts: 14

Re: Can anyone make a (key pressed) block?

nXIII wrote:

If you want, just make a new method that is this

Code:

(Sensor keyPressed: (self asciiFor: 'a')) ifTrue: [^ 'a'].
(Sensor keyPressed: (self asciiFor: 'b')) ifTrue: [^ 'b'].
...

type thing.

Type at where?

Offline

 

#23 2010-04-03 11:00:22

shadow_7283
Scratcher
Registered: 2007-11-07
Posts: 1000+

Re: Can anyone make a (key pressed) block?

nXIII wrote:

If you want, just make a new method that is this

Code:

(Sensor keyPressed: (self asciiFor: 'a')) ifTrue: [^ 'a'].
(Sensor keyPressed: (self asciiFor: 'b')) ifTrue: [^ 'b'].
...

type thing.

I tried putting that under the KeyPressed section you made on your last attempt and did not change the block specs, but now all I'm getting is aScratchStageMorph() as its value...

Edit: That's weird... It senses numbers but not letters...

Last edited by shadow_7283 (2010-04-03 11:02:49)

Offline

 

#24 2010-04-04 09:02:58

MaxtheWeirdo
Scratcher
Registered: 2010-03-18
Posts: 500+

Re: Can anyone make a (key pressed) block?

You could just stack up or blocks like this: [blocks]
<< <<  <or>  >> <or> <<  <or>  >> >> [/blocks] ect.


My website. Hall Crawler My Awesome OS
It's just marketing, guys! Nothing sinister!

Offline

 

#25 2010-04-04 09:05:06

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Can anyone make a (key pressed) block?

MaxtheWeirdo wrote:

You could just stack up or blocks like this: [blocks]
<< <<  <or>  >> <or> <<  <or>  >> >> [/blocks] ect.

Thats what i did for the byob block, just hid it all away.


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

Board footer