AllTheTimeWorld.com

alice eventsEvents: Responding to the Mouse and Keyboard

Events: Responding to the Mouse and Keyboard

Learn Alice in FREE step-by-step lessons.

Module 19: Events: Responding to the Mouse and Keyboard

The goal of this lesson is to learn to make your program more interactive
by allowing the user to control the action using the keyboard and the mouse.

Events are things that happen. In programming, some of the events that can occur are clicking or moving the mouse, typing a key on the keyboard, or other user interaction.

When these events occur, nothing will happen unless you tell the program to listen for these events and what to do when these events occur.

If we want to execute some statements when one of these events occurs, we have to tell Alice to "listen" for that event. We do this by adding a listener. We tell it what event to listen for, and what function to execute when that event occurs.

After adding an event listener, that event will trigger the execution of a procedure or function. Programmers refer to this as "Event Handling."

In this module you will learn to use event listeners to respond to the mouse and keyboard, add drag and drop and other interactive features.

In order to do this you will:

Print the lesson

Please study the material at each of the links below.

  1. A dog wags his tail continuously A dog wags his tail continuously: The addSceneActivationListener makes a dog wag his tail continuously while other actions take place.
    /alice/videos/alice-dog-wag-tail.mp4

  2. Playing a background sound Playing a background sound: To play background music use initializeEventListeners to play sound together with myFirstMethod.
    /alice/videos/alice-background-sound.mp4
  3. Click on the bear event Click on the bear event: The bear says something when the user clicks on him.
    /alice/videos/alice-mouse-click.mp4
  4. Click on several different objects Click on several different objects: Each animal says something when clicked
    /alice/videos/alice-mouse-click2.mp4
  5. Drag and Drop Drag and Drop: Using default model manipulation in event listeners lets the user drag and drop objects at run time.
    /alice/videos/alice-drag-drop.mp4
  6. Collisions Collisions: Making something happen when objects collide.
    /alice/videos/alice-collision.mp4
  7. The keypress event The keypress event: Learn how to listen for a key press (typing a letter) and respond
    /alice/videos/alice-keypress.mp4
  8. Object Mover and Key press events Object Mover and Key press events: Add object mover for the shark so that the user can move it with the arrow keys.
    /alice/videos/alice-arrowkey.mp4
  9. A Timer Event A Timer Event: Using the timer event, the penguin says "Help!" at random intervals.
    /alice/videos/alice-timer-event.mp4
  10. Self Study Questions Self Study Questions: What have you learned?

  11. Discussion Questions Discussion Questions

Active Learning

What events can you add?
Animate a fairy tale using all you have learned