O'Reilly logo

Alice 3 Cookbook by Vanesa S. Olsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Defining a key listener

In this recipe, we will make the robots dance when the user presses certain keys. The user has to press a specific key to make each robot dance. We will add code that Alice will execute when certain keys get pressed.

Getting ready

We will use an existing project that has two characters from the Looking Glass Characters gallery, biff and gina. This project has a danceAlone procedure defined for the MyBiff and the MyGina classes.

  1. Open the project saved in the Controlling an actor with the mouse recipe.
  2. Click on Edit Code, at the lower-right corner of the big scene preview. Alice will show a smaller preview of the scene and will display the Code Editor on a panel located at the right-hand side of the main window.
  3. Click on the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required