Contents

Adding JavaScript Working with Inputs and Forms

Capturing the Keyboard

This tutorial demonstrates how to capture keyboard keystrokes. Add a 'Text Box' object to the movie and set its 'Script ID' to Test.


Capturing the Keyboard 1

In the movie properties there are two keyboard events 'On Key Press' and 'On Key Release'.


Capturing the Keyboard 2

The 'On Key Press' event includes a built in variable called Key. Key is the keyboard key number. Add this script to the 'On Key Press' event to test the value of Key.



TextBoxSet("Test",Key);

Press play to test the movie. Try pressing different keys to see what happens.


Play Play

Capturing the Keyboard 4

The keyboard key A is 65. The space bar is 32. The enter key is 13. These values are based on the ASCII table. Notice that uppercase and lowercase letters have the same value. You can test for a specific key using an if statement. This example tests to see if the space bar has been pressed.



TextBoxSet("Test",Key);
if(Key==32){
alert("The space bar was pressed.");
}

Adding JavaScript Working with Inputs and Forms