To use keyboard presses within your world you need to register a keyboard callback that will monitor for key presses. There are two main ways to register callbacks. First, you can register a general callback that is triggered by any keyboard events. Second, you can register callbacks for individual keys on the fly. In addition to registering callbacks, you can also spontaneously query whether a key or a set of keys is currently being pressed.
Note: when you're referring to a specific key in the keyboard-related code, use the string associated with that key. For example, for the p key use 'p'. For any special keys that don't have a string associated with them (e.g. the arrow keys), use one of the pop-down flags that begin with viz.KEY_. So, for the down arrow, use viz.KEY_DOWN.
To register a callback for all keys, you can use viz.KEYDOWN_EVENT or viz.KEYUP_EVENT callbacks. Keydown events occur when you press a key and keyup events occur when you release a key. Note that when an event occurs, the identity of the key is returned as an input into the given function (in the example code below 'key' is the key that's been pressed).
You can also register one of these callbacks within a class.
The Vizact actions library has several commands to add keyboard callbacks for individual keys (vizact.onkeydown, vizact.whilekeydown, vizact.onkeyup). For each of these commands, provide the key id and then the command it should call and then any necessary values for the command. (Note: make sure you don't call the command by placing parentheses after it.) To remove a keyboard event use vizact.removeEvent(<event handle>). Using actions to register keyboard callbacks is particularly useful for adding and removing individual keyboard events on the fly.
Keyboard presses can also be used as a one-shot deal in action sequences such that the sequence waits until the key is pressed to proceed:
To find out if a given key is currently being pressed, use viz.key.isDown( <key> ). To find out if any member of a set of keys is being pressed, use viz.key.anyDown( <set of keys> ). To find out if all members of a set of keys are pressed, use viz.key.allDown( <set of keys> ).
Check out the section on the camera handlers to learn how to define your own keyboard-based navigation.
Camera handlers - Describes how to define viewpoint navigation with whatever input you choose.
Actions- Introduction to the vizact library of actions.