Discuss Scratch

jtmit
Scratcher
60 posts

""Simulation Blocks"

simulate key [] pressed
simulate key [] pressed for () seconds
simulate key [] pressed until <>
This would allow your program to run any cap or sensing block that detects key pressing to run, without user interaction.
This would be in the sensing category.

Last edited by jtmit (Nov. 23, 2016 22:30:32)

rh_junr
Scratcher
81 posts

""Simulation Blocks"

Would it press the key as if you pressed it or just run the cap blocks?
jtmit
Scratcher
60 posts

""Simulation Blocks"

rh_junr wrote:

Would it press the key as if you pressed it or just run the cap blocks?
I would act as though you pressed the key
(Basically running all cap blocks and sensing blocks)
It would not actually move your keyboard
MathlyCat
Scratcher
1000+ posts

""Simulation Blocks"

So ghost pressing?

Why would you want this again?
Also couldn't you just use broadcasts?:

broadcast [ v]

when I receive [ v]
Do press stuff here
jtmit
Scratcher
60 posts

""Simulation Blocks"

MathlyCat wrote:

So ghost pressing?

Why would you want this again?
Also couldn't you just use broadcasts?:

broadcast [ v]

when I receive [ v]
Do press stuff here

Yes, but if you have a really long script, and you don't want to do it twice, one for
when [a] key pressed
AND one for
when I receive [message]
If the script is really long, having two might lag your project.
JBGT
Scratcher
85 posts

""Simulation Blocks"

jtmit wrote:

simulate key [] pressed
simulate key [] pressed for () seconds
simulate key [] pressed until <>
This would allow your program to run any cap or sensing block that detects key pressing to run, without user interaction.
This would be in the sensing category.

Couldn't you just do this?

when green flag clicked
forever
wait until <<key [ v] pressed?> or <(variable) = [1]>>
do le stuff
end

and then somewhere else

when green flag clicked
forever
if <some condition> then
set [ variable] to [1]

else

set [variable] to [0]
end
end

or something like that. this was done on the fly so there could be a few bugs.

Last edited by JBGT (Nov. 25, 2016 03:53:54)

jtmit
Scratcher
60 posts

""Simulation Blocks"

JBGT wrote:

jtmit wrote:

simulate key [] pressed
simulate key [] pressed for () seconds
simulate key [] pressed until <>
This would allow your program to run any cap or sensing block that detects key pressing to run, without user interaction.
This would be in the sensing category.

Couldn't you just do this?

when green flag clicked
forever
wait until <<key [ v] pressed?> or <(variable) = [1]>>
do le stuff
end

and then somewhere else

when green flag clicked
forever
if <some condition> then
set [ variable] to [1]

else

set [variable] to [0]
end
end

or something like that. this was done on the fly so there could be a few bugs.

I guess, this was just meant to make it easier. What you show is definitely possible.

Last edited by jtmit (Nov. 26, 2016 21:48:05)

SuperHal989
Scratcher
88 posts

""Simulation Blocks"

So it would “stimulate” key presses? Would this work on only that project or would it send across your entire computer? Because making a scratch project to help me make viruses make more batch files could bring scratch to a whole new level
jtmit
Scratcher
60 posts

""Simulation Blocks"

SuperHal989 wrote:

So it would “stimulate” key presses? Would this work on only that project or would it send across your entire computer? Because making a scratch project to help me make viruses make more batch files could bring scratch to a whole new level
No, it would only affect the current scratch project.
Candylanguagegirl
Scratcher
1000+ posts

""Simulation Blocks"

I don't think this is necessary, it's pretty easy to just duplicate scripts (Right click>duplicate, in case you were wondering) to make use of Mathlycat's workaround. If you really don't want to make a few extra clicks, you can always make a custom block and just use that.

Last edited by Candylanguagegirl (Nov. 27, 2016 23:51:00)

_nix
Scratcher
1000+ posts

""Simulation Blocks"

Custom blocks serve your purpose (for most (event-based) purposes):

when [a v] key pressed
my action

forever // every 5 seconds, "simulate" pressing the A key
my action
wait (5) secs
end

define my action
play drum (1 v) for (0.25) beats

If your project doesn't happen to be event-based like that you can use variables.

when gf clicked
set [simulated right key pressed? v] to [0]
forever
if <<key [right arrow v] pressed?> or <(simulated right key pressed?) = [1]>> then
set [right key pressed? v] to [1]
else
set [right key pressed? v] to [0]
end
end

when flag clicked
forever
if <(right key pressed?) = [1]> then
move (5) steps
end
end

when flag clicked
forever // every 5 seconds, "simulate" pressing the right key for 1 second
wait (5) secs
set [simulated right key pressed? v] to [1]
wait (1) secs
set [simulated right key pressed? v] to [0]
end

Last edited by _nix (Nov. 28, 2016 12:21:10)

MathlyCat
Scratcher
1000+ posts

""Simulation Blocks"

jtmit wrote:

JBGT wrote:

jtmit wrote:

simulate key [] pressed
simulate key [] pressed for () seconds
simulate key [] pressed until <>
This would allow your program to run any cap or sensing block that detects key pressing to run, without user interaction.
This would be in the sensing category.

Couldn't you just do this?

when green flag clicked
forever
wait until <<key [ v] pressed?> or <(variable) = [1]>>
do le stuff
end

and then somewhere else

when green flag clicked
forever
if <some condition> then
set [ variable] to [1]

else

set [variable] to [0]
end
end

or something like that. this was done on the fly so there could be a few bugs.

I guess, this was just meant to make it easier. What you show is definitely possible.
It's so much easier with variables and broadcasts rather than trying to fit your blocks into script.
Really, it's better for Scratcher's to learn/teach themselves how to produce such script, because in reality, other programming languages don't always have specific functions that simulate a button press.

Powered by DjangoBB