I’m using Kojo to teach kids programming in Sweden.
That's great to hear.
I think the environment is great!
Thank you.
I would like to test if a key is pressed or not
Is there an easy way of doing this?
Within Kojo, you can currently work with the keyboard in a couple of different ways:
- With turtles; here's an example:
clear()
clearOutput
repeat (2) {
forward(readInt("How may steps"))
right(readInt("How many degrees"))
}
- With Staging shapes; here's an example:
val S = Staging
S.clear()
val c = S.circle(S.point(10, 10), 100)
c.setFillColor(green)
// click on shape to activate key handling
c.onKeyPress { k =>
k match {
case Kc.VK_RIGHT => c.translate(-10, 0)
case Kc.VK_LEFT => c.translate(10, 0)
case _ =>
}
}
Anyway of polling the keybord with the builtin stuff?
I just played with adding builtin capability so that you could do things like the following:
clear()
setAnimationDelay(100)
onKeyPress { k =>
k match {
case Kc.VK_LEFT =>
setHeading(180)
forward(100)
case Kc.VK_RIGHT =>
setHeading(0)
forward(100)
case Kc.VK_UP =>
setHeading(90)
forward(100)
case Kc.VK_DOWN =>
setHeading(270)
forward(100)
}
}
Does that sound useful for the kinds of things that you are trying to do.
I'm open to other API suggestions (and I do need to look at the Processing stuff)…
Cheers,
- Lalit