[MWForum]Microworlds Pro Key Commands
Daniel Ajoy
mwforum@lists.mathcats.com
Sat, 21 Dec 2002 12:40:06 -0500
On 21 Dec 2002 at 8:20, Ralph Wege wrote:
> What are the commands to make the turtle respond to keystrokes? In
> particular, I want to use the arrow keys to control the turtle's
> movements in direction aned speed, kind of like it is a spacecraft with
> thrusters. I know that you use ASCII codes but I don't know the commands
> to activate the keys. Please help.
>
> Ralph
>
The following is what Wendy wrote to the LogoForum last year,
Michael Tempel talks about this same thing here:
http://el.media.mit.edu/logo-foundation/pubs/logoupdate/v7n3/games2.html
Daniel
OpenWorld Learning
>From Wendy Petti <wpetti@mathcats.com> Thu Nov 29 10:36:39 2001
To: LogoForum@yahoogroups.com
Subject: Re: Web help
In terms of programming arrow keys in MicroWorlds, it is simple
enough to combine both the PC and the Mac ascii codes into one
procedure. I learned this from Michael Tempel when we were both
visiting OpenWorld Learning in Colorado last June. But he used
different ascii numbers for the arrow keys on the PC than Jeff has
given. Here is what Michael uses. (He adds a "go" button and
procedure to set the turtle in motion and activate the key
programming. The turtle's command is FD 1, set to many times. With
today's faster computers, it might be better to give the turtle the
command FD 1 / 10 or another fraction, or if you have a slider named
speed then the turtle's command could be FD SPEED / 10 and you'd
have to figure out an appropriate maximum for the speed slider). The
first four ascii codes are for PC (different from Jeff's numbers);
the second four are the Mac codes which Jeff also uses:
to go
t1,
clickon
forever [direct readchar]
end
to direct :key
if (ascii :key) = 37 [ seth 270]
if (ascii :key) = 39 [ seth 90]
if (ascii :key) = 38 [ seth 0]
if (ascii :key) = 40 [ seth 180]
if (ascii :key) = 28 [ seth 270]
if (ascii :key) = 29 [ seth 90]
if (ascii :key) = 30 [ seth 0]
if (ascii :key) = 31 [ seth 180]
if :key = "s [stopall]
end
Of course, another solution would be to use four letter keys instead
of using arrow keys. That way, the same four commands work for PC or
Mac.
In fact, if you program two sets of letter keys, you can have four
keys control one turtle and four control another turtle so that two
students can compete with each other to see which turtle can get
through the maze more quickly (or accomplish some other goal). You
can use keys A, S, D, and W to control one turtle and keys J, K, L,
and I to control the other one. (Of course, in that case you could
not use the S key to stop the procedure. You could include
a "stopall" button or program a different key.) You need to designate
which turtle will respond to each key. So a two-turtle control
procedure might look like this:
to direct :key
if :key = "a [t1, seth 270]
if :key = "s [t1, seth 180]
if :key = "d [t1, seth 90]
if :key = "w [t1, seth 0]
if :key = "j [t2, seth 270]
if :key = "k [t2, seth 180]
if :key = "l [t2, seth 90]
if :key = "i [t2, seth 0]
end
(If you really want to form a crowd around one computer, you could
program the arrow keys too, for a third student to control a third
turtle!)
Wendy Petti
MicroWorlds in Action
http://www.openworldlearning.org/owlb/projects.htm