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-
and X
-downcatch-key-
, where X
-upX
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 such cases, you can still catch the event using the hexadecimal ASCII equivalent for the character. In the
case of the space bar, the valid breve method name would be
catch-key-0x20-down
. Consult an ASCII
table for more information. Don't forget to add 0x
in front of hexadecimal values!
In addition to catching regular ASCII characters, similar methods may be used to catch the arrow keys:
catch-key-left-down catch-key-left-up catch-key-right-down catch-key-right-up catch-key-up-down catch-key-up-up catch-key-down-down catch-key-down-up
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 continuous event, then use the "up" callback to deactivate the event.