LzKeys

Keyboard input service.

This service handles keyboard input events.

Here is a simple example:

Example 1. LzKeys
<canvas height="140" debug="true">
  <handler name="onkeydown" reference="LzKeys" args="k">
    Debug.write("key " + k + " down");
  </handler>
  <handler name="onkeyup" reference="LzKeys" args="k">
    Debug.write("key " + k + " up");
  </handler>
  <method name="pressA">
    Debug.write("A pressed");
  </method>
  <handler name="oninit">
    del = new LzDelegate(this, "pressA");
    LzKeys.callOnKeyCombo(del, ["A"]);
  </handler> 
</canvas>
Attributes
Name Usage Type (Tag) Type (JS) Default Category
downKeysArray JS only Array of Number   readonly
  An array of currently pressed key codes.

downKeysHash JS only Object   readonly
  A hash where each of the keys that is currently down on the keyboard is set to true.

keyCodes JS only Object   readonly
  A hash that maps key names to key codes.

mousewheeldelta JS only Number   readonly
  the amount the mouse wheel last moved. Use onmousewheeldelta to learn when this value changes.



Methods

callOnKeyCombo()
LzKeys.callOnKeyCombo(d, kCArr)

Instructs the service to call the given delegate whenever the given key combination is pressed. The names for recognized special keys are (case-insensitive):

  • numbpad0
  • numbpad1
  • numbpad2
  • numbpad3
  • numbpad4
  • numbpad5
  • numbpad6
  • numbpad7
  • numbpad8
  • numbpad9
  • multiply
  • enter
  • subtract
  • decimal
  • divide
  • f1
  • f2
  • f3
  • f4
  • f5
  • f6
  • f7
  • f8
  • f9
  • f10
  • f11
  • f12
  • backspace
  • tab
  • clear
  • enter
  • shift
  • control
  • alt
  • capslock
  • esc
  • spacebar
  • pageup
  • pagedown
  • end
  • home
  • leftarrow
  • uparrow
  • rightarrow
  • downarrow
  • insert
  • help
  • numlock
  • add
  • delete
  • 0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • [
  • @
  • #
  • $
  • %
  • ^
  • &
  • *
  • *
  • (
  • )
  • ;
  • :
  • =
  • +
  • -
  • _
  • /
  • ?
  • ~
  • [
  • {
  • \
  • |
  • ]
  • }
  • "
  • '

Parameters
Name Type Desc
d LzDelegate The delegate to be called when the keycombo is down.
kCArr [String] Array of strings indicating which keys constitute the keycombo. This array may be in any order.


getDownKeys()
LzKeys.getDownKeys()
Returns
Type Desc
[Number] array of keys codes that are currently down


isKeyDown()
LzKeys.isKeyDown(k)
Parameters
Name Type Desc
k String The name of the key to check for downness or an array of key names (e.g. ['shift', 'tab']
Returns
Type Desc
Boolean indicating whether the given key is down.


removeKeyComboCall()
LzKeys.removeKeyComboCall(d, kCArr)

Removes the request to call the delegate on the keycombo.

Parameters
Name Type Desc
d LzDelegate The delegate that was to be called when the keycombo was down.
kCArr [String] An array of strings indicating which keys constituted the keycombo.



Events
Name Description
onkeydown None
onkeyup None