Input Class
Publishes key and mouse events that occur on the parent Viewer's Canvas.
Overview
- Each Viewer provides an Input on itself as a read-only property.
Example
In this example, we're subscribing to some mouse and key events that will occur on a Viewer's Canvas.
var viewer = new BIMSURFER.Viewer(...);
var input = viewer.input;
// We'll save a handle to this subscription
// to show how to unsubscribe, further down
var handle = input.on("mousedown", function(coords) {
console.log("Mouse down at: x=" + coords[0] + ", y=" + coords[1]);
});
input.on("mouseup", function(coords) {
console.log("Mouse up at: x=" + coords[0] + ", y=" + coords[1]);
});
input.on("mouseclicked", function(coords) {
console.log("Mouse clicked at: x=" + coords[0] + ", y=" + coords[1]);
});
input.on("dblclick", function(coords) {
console.log("Double-click at: x=" + coords[0] + ", y=" + coords[1]);
});
input.on("keydown", function(keyCode) {
switch (keyCode) {
case this.KEY_A:
console.log("The 'A' key is down");
break;
case this.KEY_B:
console.log("The 'B' key is down");
break;
case this.KEY_C:
console.log("The 'C' key is down");
break;
default:
console.log("Some other key is down");
}
});
input.on("keyup", function(keyCode) {
switch (keyCode) {
case this.KEY_A:
console.log("The 'A' key is up");
break;
case this.KEY_B:
console.log("The 'B' key is up");
break;
case this.KEY_C:
console.log("The 'C' key is up");
break;
default:
console.log("Some other key is up");
}
});
// TODO: ALT and CTRL keys etc
Unsubscribing from Events
In the snippet above, we saved a handle to one of our event subscriptions.
We can then use that handle to unsubscribe again, like this:
input.off(handle);
Item Index
Properties
- className
- destroyed
- id
- Items in this map
- KEY_A
- KEY_ADD
- KEY_ALT
- KEY_B
- KEY_BACK_SLASH
- KEY_BACKSPACE
- KEY_C
- KEY_CAPS_LOCK
- KEY_CLOSE_BRACKET
- KEY_COMMA
- KEY_CTRL
- KEY_D
- KEY_DASH
- KEY_DECIMAL_POINT
- KEY_DELETE
- KEY_DIVIDE
- KEY_DOWN_ARROW
- KEY_E
- KEY_END
- KEY_ENTER
- KEY_EQUAL_SIGN
- KEY_ESCAPE
- KEY_F
- KEY_F1
- KEY_F10
- KEY_F11
- KEY_F12
- KEY_F2
- KEY_F3
- KEY_F4
- KEY_F5
- KEY_F6
- KEY_F7
- KEY_F8
- KEY_F9
- KEY_FORWARD_SLASH
- KEY_G
- KEY_GRAVE_ACCENT
- KEY_H
- KEY_HOME
- KEY_I
- KEY_INSERT
- KEY_J
- KEY_K
- KEY_L
- KEY_LEFT_ARROW
- KEY_LEFT_WINDOW
- KEY_M
- KEY_MULTIPLY
- KEY_N
- KEY_NUM_0
- KEY_NUM_1
- KEY_NUM_2
- KEY_NUM_3
- KEY_NUM_4
- KEY_NUM_5
- KEY_NUM_6
- KEY_NUM_7
- KEY_NUM_8
- KEY_NUM_9
- KEY_NUM_LOCK
- KEY_NUMPAD 2
- KEY_NUMPAD_0
- KEY_NUMPAD_1
- KEY_NUMPAD_3
- KEY_NUMPAD_4
- KEY_NUMPAD_5
- KEY_NUMPAD_6
- KEY_NUMPAD_7
- KEY_NUMPAD_8
- KEY_NUMPAD_9
- KEY_O
- KEY_OPEN_BRACKET
- KEY_P
- KEY_PAGE_DOWN
- KEY_PAGE_UP
- KEY_PAUSE_BREAK
- KEY_PERIOD
- KEY_Q
- KEY_R
- KEY_RIGHT_ARROW
- KEY_RIGHT_WINDOW
- KEY_S
- KEY_SCROLL_LOCK
- KEY_SELECT
- KEY_SEMI_COLON
- KEY_SHIFT
- KEY_SINGLE_QUOTE
- KEY_SPACE
- KEY_SUBTRACT
- KEY_T
- KEY_TAB
- KEY_U
- KEY_UP_ARROW
- KEY_V
- KEY_W
- KEY_X
- KEY_Y
- KEY_Z
- metadata
- viewer
Methods
destroy
()
error
-
message
Logs an error for this component to the JavaScript console.
The console message will have this format: [ERROR] <component id>: <message>
Parameters:
-
message
StringThe message to log
fire
-
event
-
value
-
[forget=false]
Fires an event on this component.
Notifies existing subscribers to the event, retains the event to give to any subsequent notifications on that location as they are made.
Parameters:
-
event
StringThe event type name
-
value
ObjectThe event
-
[forget=false]
Boolean optionalWhen true, does not retain for subsequent subscribers
log
-
message
Logs a console debugging message for this component.
The console message will have this format: [LOG] <component id>: <message>
Parameters:
-
message
StringThe message to log
off
-
handle
Parameters:
-
handle
StringSubscription handle
on
-
event
-
callback
-
[scope=this]
Subscribes to an event on this component.
The callback is be called with this component as scope.
Parameters:
-
event
StringPublication event
-
callback
FunctionCalled when fresh data is available at the event
-
[scope=this]
Object optionalScope for the callback
Returns:
Handle to the subscription, which may be used to unsubscribe with {@link #off}.
once
-
event
-
callback
-
[scope=this]
Subscribes to the next occurrence of the given event, then un-subscribes as soon as the event is handled.
Parameters:
-
event
StringData event to listen to
-
callback
Function(data)Called when fresh data is available at the event
-
[scope=this]
Object optionalScope for the callback
warn
-
message
Logs a warning for this component to the JavaScript console.
The console message will have this format: [WARN] <component id>: <message>
Parameters:
-
message
StringThe message to log
Properties
className
String
final
JavaScript class name for this Component.
destroyed
Boolean
True as soon as this Component has been destroyed
Items in this map
Unknown
KEY_A
Number
final
Code for the A key.
KEY_ADD
Number
final
Code for the ADD key.
KEY_ALT
Number
final
Code for the ALT key.
KEY_B
Number
final
Code for the B key.
KEY_BACK_SLASH
Number
final
Code for the BACK_SLASH key.
KEY_BACKSPACE
Number
final
Code for the BACKSPACE key.
KEY_C
Number
final
Code for the C key.
KEY_CAPS_LOCK
Number
final
Code for the CAPS_LOCK key.
KEY_CLOSE_BRACKET
Number
final
Code for the CLOSE_BRACKET key.
KEY_COMMA
Number
final
Code for the COMMA key.
KEY_CTRL
Number
final
Code for the CTRL key.
KEY_D
Number
final
Code for the D key.
KEY_DASH
Number
final
Code for the DASH key.
KEY_DECIMAL_POINT
Number
final
Code for the DECIMAL POINT key.
KEY_DELETE
Number
final
Code for the DELETE key.
KEY_DIVIDE
Number
final
Code for the DIVIDE key.
KEY_DOWN_ARROW
Number
final
Code for the DOWN_ARROW key.
KEY_E
Number
final
Code for the E key.
KEY_END
Number
final
Code for the END key.
KEY_ENTER
Number
final
Code for the ENTER key.
KEY_EQUAL_SIGN
Number
final
Code for the EQUAL_SIGN key.
KEY_ESCAPE
Number
final
Code for the ESCAPE key.
KEY_F
Number
final
Code for the F key.
KEY_F1
Number
final
Code for the F1 key.
KEY_F10
Number
final
Code for the F10 key.
KEY_F11
Number
final
Code for the F11 key.
KEY_F12
Number
final
Code for the F12 key.
KEY_F2
Number
final
Code for the F2 key.
KEY_F3
Number
final
Code for the F3 key.
KEY_F4
Number
final
Code for the F4 key.
KEY_F5
Number
final
Code for the F5 key.
KEY_F6
Number
final
Code for the F6 key.
KEY_F7
Number
final
Code for the F7 key.
KEY_F8
Number
final
Code for the F8 key.
KEY_F9
Number
final
Code for the F9 key.
KEY_FORWARD_SLASH
Number
final
Code for the FORWARD_SLASH key.
KEY_G
Number
final
Code for the G key.
KEY_GRAVE_ACCENT
Number
final
Code for the GRAVE_ACCENT key.
KEY_H
Number
final
Code for the H key.
KEY_HOME
Number
final
Code for the HOME key.
KEY_I
Number
final
Code for the I key.
KEY_INSERT
Number
final
Code for the INSERT key.
KEY_J
Number
final
Code for the J key.
KEY_K
Number
final
Code for the K key.
KEY_L
Number
final
Code for the L key.
KEY_LEFT_ARROW
Number
final
Code for the LEFT_ARROW key.
KEY_LEFT_WINDOW
Number
final
Code for the LEFT_WINDOW key.
KEY_M
Number
final
Code for the M key.
KEY_MULTIPLY
Number
final
Code for the MULTIPLY key.
KEY_N
Number
final
Code for the N key.
KEY_NUM_0
Number
final
Code for the 0 key.
KEY_NUM_1
Number
final
Code for the 1 key.
KEY_NUM_2
Number
final
Code for the 2 key.
KEY_NUM_3
Number
final
Code for the 3 key.
KEY_NUM_4
Number
final
Code for the 4 key.
KEY_NUM_5
Number
final
Code for the 5 key.
KEY_NUM_6
Number
final
Code for the 6 key.
KEY_NUM_7
Number
final
Code for the 7 key.
KEY_NUM_8
Number
final
Code for the 8 key.
KEY_NUM_9
Number
final
Code for the 9 key.
KEY_NUM_LOCK
Number
final
Code for the NUM_LOCK key.
KEY_NUMPAD 2
Number
final
Code for the number pad 2 key.
KEY_NUMPAD_0
Number
final
Code for the number pad 0 key.
KEY_NUMPAD_1
Number
final
Code for the number pad 1 key.
KEY_NUMPAD_3
Number
final
Code for the number pad 3 key.
KEY_NUMPAD_4
Number
final
Code for the number pad 4 key.
KEY_NUMPAD_5
Number
final
Code for the number pad 5 key.
KEY_NUMPAD_6
Number
final
Code for the number pad 6 key.
KEY_NUMPAD_7
Number
final
Code for the number pad 7 key.
KEY_NUMPAD_8
Number
final
Code for the number pad 8 key.
KEY_NUMPAD_9
Number
final
Code for the number pad 9 key.
KEY_O
Number
final
Code for the O key.
KEY_OPEN_BRACKET
Number
final
Code for the OPEN_BRACKET key.
KEY_P
Number
final
Code for the P key.
KEY_PAGE_DOWN
Number
final
Code for the PAGE_DOWN key.
KEY_PAGE_UP
Number
final
Code for the PAGE_UP key.
KEY_PAUSE_BREAK
Number
final
Code for the PAUSE_BREAK key.
KEY_PERIOD
Number
final
Code for the PERIOD key.
KEY_Q
Number
final
Code for the Q key.
KEY_R
Number
final
Code for the R key.
KEY_RIGHT_ARROW
Number
final
Code for the RIGHT_ARROW key.
KEY_RIGHT_WINDOW
Number
final
Code for the RIGHT_WINDOW key.
KEY_S
Number
final
Code for the S key.
KEY_SCROLL_LOCK
Number
final
Code for the SCROLL_LOCK key.
KEY_SELECT
Number
final
Code for the SELECT key.
KEY_SEMI_COLON
Number
final
Code for the SEMI_COLON key.
KEY_SHIFT
Number
final
Code for the SHIFT key.
KEY_SINGLE_QUOTE
Number
final
Code for the SINGLE_QUOTE key.
KEY_SPACE
Number
final
Code for the SPACE key.
KEY_SUBTRACT
Number
final
Code for the SUBTRACT key.
KEY_T
Number
final
Code for the T key.
KEY_TAB
Number
final
Code for the TAB key.
KEY_U
Number
final
Code for the U key.
KEY_UP_ARROW
Number
final
Code for the UP_ARROW key.
KEY_V
Number
final
Code for the V key.
KEY_W
Number
final
Code for the W key.
KEY_X
Number
final
Code for the X key.
KEY_Y
Number
final
Code for the Y key.
KEY_Z
Number
final
Code for the Z key.
metadata
Object
Metadata on this component.
Events
dblclick
Event Payload:
-
value
Number, NumberThe mouse coordinates within the Canvas,
destroyed
Fired when this Component is destroyed.
keydown
Event Payload:
-
value
NumberThe key code, for example KEY_LEFT_ARROW,
keyup
Event Payload:
-
value
NumberThe key code, for example KEY_LEFT_ARROW,
mouseclicked
Event Payload:
-
value
Number, NumberThe mouse coordinates within the Canvas,
mousedown
Event Payload:
-
value
Number, NumberThe mouse coordinates within the Canvas,
mousedown
Event Payload:
-
value
Number, NumberThe mouse coordinates within the Canvas,
mouseup
Event Payload:
-
value
Number, NumberThe mouse coordinates within the Canvas,