O'Reilly logo

Lingo in a Nutshell by Bruce A. Epstein

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

Chapter 10. Keyboard Events

Keyboard Events

Whenever a standard (non-modifier) key is pressed or released, Director generates a keyDown or keyUp event. Only script attached to editable field sprites, frame scripts, and movie scripts receive keyboard events. All field sprites, even non-editable ones, can receive the standard sprite events (mouseUp, mouseDown, mouseEnter, mouseLeave, and so on) Refer to Chapter 7, for details on manipulating strings and text. See especially Example 7-7. Refer to Chapter 12, Text and Fields, in Director in a Nutshell for more details on working with fields.

Tip

Keyboard characters are sent automatically to an editable field sprite with keyboard focus, unless the keyDown event is intercepted by an onkeyDown handler in a sprite or castmember script first (or explicitly stopped in the keyDownScript primary event handler).

The key being pressed “rides along” with the keyDown event. If an editable field sprite receives the keyDown event, the last key pressed will be added to the field. Non-editable fields, editable fields without keyboard focus, and non-field sprites do not receive keyDown and keyUp events. Rich text sprites can not be edited at run time. You must use field sprites for dynamic text.

Your keyDown handler will be called even when special characters, such as the arrow keys, are pressed. Simply pass these onto the field sprite.

Tip

Fields will automatically recognize the arrow keys and Delete key to perform rudimentary editing (see "Editing Keys

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