Contents |
|
Adding JavaScript | Working with Inputs and Forms |
This tutorial demonstrates how to capture keyboard keystrokes. Add a 'Text Box' object to the movie and set its 'Script ID' to Test.
In the movie properties there are two keyboard events 'On Key Press' and 'On Key Release'.
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.
Press play to test the movie. Try pressing different keys to see what happens.
Play |
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.
Adding JavaScript | Working with Inputs and Forms |