PhotonUI logo

PhotonUI

A javascript framework to create user interfaces

KeyboardManager

This component allows you to track keyboard state in an intuitive way.

Class Reference

Callbacks

One can register to keyboard callbacks:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Add a field to display things
var field = new photonui.TextAreaField({
placeholder: "Start writing here!",
rows: 20
});
photonui.domInsert(field, "demo");

// Create our keyboard manager
var kb = new photonui.KeyboardManager(field, {safe: false});

// What to write to our label
var keys = [];
var printKeys = function() {
field.value = "";
for (var key in keys)
field.value += key + " " + keys[key] + "\n";
};

// Register to basic callbacks
kb.registerCallback("kb1", "key-down", function(manager, kstate) {
keys[kstate.key] = "down";
printKeys();
});

kb.registerCallback("kb2", "key-hold", function(manager, kstate) {
keys[kstate.key] = "hold";
printKeys();
});

kb.registerCallback("kb3", "key-up", function(manager, kstate) {
keys[kstate.key] = "up";
printKeys();
});