Util.Keyboard

Keyboard shortcut handler object for easy mapping of keyboard combinations with buttons, links or JavaScript functions.

Functions

Util.Keyboard.addKey

Definition

Name
Util.Keyboard.addKey
Shorthand
u.k.addKey
Syntax
Void = Util.Keyboard.addKey( Node node, String key [, JSON _options ] );

Description

Add a keyboard shortcut, with default callback to node.clicked. Optional custom callback and metakey (CMD or CTRL) requirement. As default metakey is required.

Custom 'ESC' shortcut for [ESC]-key - does not require metakey.

Shortcut can be assigned multiple times to different nodes and/or callbacks.

Hidden or removed nodes are not executed and automatically removed from shortcuts queue.

Parameters

node
Node node to map shortcut to
key
String shortcut key
_options
JSON Optional shortcut options
Options
callback
Custom callback function name
metakey
Is metakey required, default true

Returns

Void

Examples

u.k.addKey(scene, "k");

Will invoke scene.clicked when k+cmd/ctrl is pressed.

u.k.addKey(scene, "k", {"metakey":false});

Will invoke scene.clicked when k is pressed.

u.k.addKey(scene, "ESC", {"callback":"escaped"});

Will invoke scene.escaped when [ESC] is pressed.

Uses

JavaScript
  • typeof
  • switch ... case
  • for ... in
  • String.fromCharCode
Manipulator
  • Util.nodeWithin
  • Util.Events.addEvent

Files

Main file

  • u-keyboard.js

Segment support files

  • none

Segment dependencies

desktop_edge
u-keyboard.js + u-events.js + u-dom.js
desktop_ie11
u-keyboard.js + u-events.js + u-dom.js
desktop
u-keyboard.js + u-events.js + u-dom.js
desktop_ie10
u-keyboard.js + u-events.js + u-dom.js + u-dom-desktop_ie10.js
desktop_ie9
u-keyboard.js + u-events.js + u-dom.js + u-dom-desktop_ie10.js
desktop_light
u-keyboard.js + u-events.js + u-events-desktop_light.js + u-dom.js + u-dom-desktop_light.js
tablet
u-keyboard.js + u-events.js + u-dom.js
tablet_light
u-keyboard.js + u-events.js + u-dom.js
smartphone
u-keyboard.js + u-events.js + u-dom.js
mobile
not tested
mobile_light
not tested
tv
u-keyboard.js + u-events.js + u-events-desktop_light.js + u-dom.js + u-dom-desktop_light.js
seo
not supported