7.2. Responding to Keyboard Events

Catching keyboard events lets a simulation execute certain actions in response to user keypresses. To catch keyboard events, simply implement methods in your simulation with names like catch-key-X-down and catch-key-X-up, where X is any letter or number, uppercase or lowercase.

In the event that the key you want to catch is not a letter or number, then the method names described above may not work, due to conflicts with the steve language. If you tried to catch the space bar, for example, using a method named catch-key- -up, breve would get confused—the same is true of most punctuation as well. In this case, you can still catch the event using the hexadecimal ASCII equivalent for the character. In this case of the space bar, the valid breve method name would be catch-key-0x20-down. Consult an ASCII table for more information. And don't for get the 0x in front of hexadecimal values!

When a key is pressed down, only one call to the "down" method is made (as opposed to repeated calls until the button is released). And likewise, only a single call to the "up" method is made. If you wish for an action to continue for as long as a key is pressed down, then you should have the "down" callback set a flag or call a method which will trigger a repeating or constant event, then have the "up" callback deactivate the event.