WLEvent.onKey()

Overview

Set an event handler for the specified key code in the current or specified scope.

The onKey function uses the buildOnKey function to parse the keyCode parameter and then calls the on function.

This only handles key values that are mapped. If the Velocity Client key test only shows a code and does not show a value for the key, you must use Keyboard.mapKeypress() to map the key first.

Format

WLEvent.onKey(keyCode,funcRef,scope);

Parameter Description Type Required Notes
keyCode The key code that invokes this function when pressed. Integer Required May be the numeric value of a key, the string-encoded numeric value of a key, or a named key. For key values, see Keyboard Codes and Commands.
funcRef The function triggered when the key event is triggered. Function Required
scope The type of scope this key event handler is associated with. For information about scopes, see Understanding scopes. String Optional If no value is provided, the current scope is used. Returns false if the scope doesn't exist, true if the handler was successfully registered.

Example

Copy
// This is a hard-coded example of the WLEvent.onKey script. 
// Triggers the onError function for a session when the specified key is pressed.
 
WLEvent.onKey(13,myHandler,"session");