wired:input
Local pointer and device input, either aimed at specific prims or global to the device.
A pointer is the desktop cursor or a VR hand. Trigger activates targets; grip grabs them.
Interface types
Uses vec2, vec3, ray, transform, prim-ref.
pointer-kind
screen | Desktop cursor ray projected from the camera. |
left-hand | |
right-hand |
button
trigger | |
grip | |
menu |
hit
Collider hit from a pointer ray, in the calling script's document frame.
target: option<prim-ref> | Hit prim, if the collider belongs to a document. |
position: vec3 | |
normal: vec3 | |
distance: f32 |
key
Physical key identified by US keyboard position regardless of active layout (not text characters).
a | |
b | |
c | |
d | |
e | |
f | |
g | |
h | |
i | |
j | |
k | |
l | |
m | |
n | |
o | |
p | |
q | |
r | |
s | |
t | |
u | |
v | |
w | |
x | |
y | |
z | |
digit0 | |
digit1 | |
digit2 | |
digit3 | |
digit4 | |
digit5 | |
digit6 | |
digit7 | |
digit8 | |
digit9 | |
f1 | |
f2 | |
f3 | |
f4 | |
f5 | |
f6 | |
f7 | |
f8 | |
f9 | |
f10 | |
f11 | |
f12 | |
space | |
enter | |
escape | |
tab | |
backspace | |
delete | |
insert | |
home | |
end | |
page-up | |
page-down | |
arrow-up | |
arrow-down | |
arrow-left | |
arrow-right | |
shift-left | |
shift-right | |
control-left | |
control-right | |
alt-left | |
alt-right | |
super-left | |
super-right | |
minus | |
equal | |
bracket-left | |
bracket-right | |
backslash | |
semicolon | |
quote | |
backquote | |
comma | |
period | |
slash |
action
Event routing by listener kind:
| action | targeted | device |
|---|---|---|
| trigger, grip | yes | yes |
| menu | no | yes |
| scroll | yes | yes |
| entered, left | yes | no |
| key | no | yes |
pressed(button) | |
released(button) | Targeted listeners receive the matching release for any press they received, even if the pointer moved away. |
scroll(vec2) | Scroll wheel delta on each axis. |
entered | |
left | |
key-pressed(key) | Key pressed (non-repeating). Carries the screen ray with no hit. |
key-released(key) |
input-event
Input event with ray and hit in the calling script's document frame.
pointer: pointer-kind | |
action: action | |
ray: ray | |
hit: option<hit> |
pointer
Snapshot of a pointer this frame, with ray and hit in the calling
script's document frame.
kind: pointer-kind | |
active: bool | true when tracked this frame; inactive pointers zero all other fields. |
pose: transform | Full pose (including roll); ray starts at translation along forward. |
ray: ray | |
trigger: f32 | Trigger pull (0..1). |
grip: f32 | Grip pull (0..1). |
axis: vec2 | Thumbstick deflection (-1..1 per axis). |
hit: option<hit> |
input-subscription
Queues up to 64 input events.
drain
drain: func(max: u32) -> list<input-event>dropped
dropped: func() -> u64Interface targeted
Uses prim-id, error, document, input-subscription.
Pointer input targeted at a specific prim subtree.
listen
listen: func(document: borrow<document>, prim: prim-id) -> result<input-subscription, error>Subscribes to pointer events hitting prim or its descendants in a
writable document. Requires a collider on the target prims.
Interface device
Uses error, input-subscription, pointer, pointer-kind.
Global input from the local user's devices.
control
Built-in host control that a script can claim.
grip | Default object grab. |
stick | Thumbstick locomotion and turning. |
claim
Suppresses default host handling for one pointer control while held.
Listeners and pointers still observe input; host handling resumes once
all claims on that control are dropped.
listen
listen: func() -> result<input-subscription, error>pointers
Returns every pointer kind, active or inactive.
take-control
take-control: func(pointer: pointer-kind, control: control) -> result<claim, error>Claims control on pointer from the host until the returned handle is
dropped.
Source
/// Local pointer and device input, either aimed at specific prims or global to
/// the device.
///
/// A pointer is the desktop cursor or a VR hand. Trigger activates targets;
/// grip grabs them.
package wired:input;
interface types {
use wired:core/math.{vec2, vec3, ray, transform};
use wired:core/ids.{prim-ref};
enum pointer-kind {
/// Desktop cursor ray projected from the camera.
screen,
left-hand,
right-hand,
}
enum button {
trigger,
grip,
menu,
}
/// Collider hit from a pointer ray, in the calling script's document frame.
record hit {
/// Hit prim, if the collider belongs to a document.
target: option<prim-ref>,
position: vec3,
normal: vec3,
distance: f32,
}
/// Physical key identified by US keyboard position regardless of active
/// layout (not text characters).
enum key {
a, b, c, d, e, f, g, h, i, j, k, l, m,
n, o, p, q, r, s, t, u, v, w, x, y, z,
digit0, digit1, digit2, digit3, digit4,
digit5, digit6, digit7, digit8, digit9,
f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12,
space, enter, escape, tab, backspace, delete, insert,
home, end, page-up, page-down,
arrow-up, arrow-down, arrow-left, arrow-right,
shift-left, shift-right, control-left, control-right,
alt-left, alt-right, super-left, super-right,
minus, equal, bracket-left, bracket-right, backslash,
semicolon, quote, backquote, comma, period, slash,
}
/// Event routing by listener kind:
///
/// | action | targeted | device |
/// |----------------------|----------|--------|
/// | trigger, grip | yes | yes |
/// | menu | no | yes |
/// | scroll | yes | yes |
/// | entered, left | yes | no |
/// | key | no | yes |
variant action {
pressed(button),
/// Targeted listeners receive the matching release for any press they
/// received, even if the pointer moved away.
released(button),
/// Scroll wheel delta on each axis.
scroll(vec2),
entered,
left,
/// Key pressed (non-repeating). Carries the screen ray with no hit.
key-pressed(key),
key-released(key),
}
/// Input event with `ray` and `hit` in the calling script's document frame.
record input-event {
pointer: pointer-kind,
action: action,
ray: ray,
hit: option<hit>,
}
/// Snapshot of a pointer this frame, with `ray` and `hit` in the calling
/// script's document frame.
record pointer {
kind: pointer-kind,
/// `true` when tracked this frame; inactive pointers zero all other fields.
active: bool,
/// Full pose (including roll); `ray` starts at `translation` along forward.
pose: transform,
ray: ray,
/// Trigger pull (`0..1`).
trigger: f32,
/// Grip pull (`0..1`).
grip: f32,
/// Thumbstick deflection (`-1..1` per axis).
axis: vec2,
hit: option<hit>,
}
/// Queues up to 64 input events.
resource input-subscription {
drain: func(max: u32) -> list<input-event>;
dropped: func() -> u64;
}
}
/// Pointer input targeted at a specific prim subtree.
interface targeted {
use wired:core/ids.{prim-id};
use wired:core/error.{error};
use wired:scene/document.{document};
use types.{input-subscription};
/// Subscribes to pointer events hitting `prim` or its descendants in a
/// writable document. Requires a collider on the target prims.
listen: func(document: borrow<document>, prim: prim-id) -> result<input-subscription, error>;
}
/// Global input from the local user's devices.
interface device {
use wired:core/error.{error};
use types.{input-subscription, pointer, pointer-kind};
/// Built-in host control that a script can claim.
enum control {
/// Default object grab.
grip,
/// Thumbstick locomotion and turning.
stick,
}
/// Suppresses default host handling for one pointer control while held.
/// Listeners and `pointers` still observe input; host handling resumes once
/// all claims on that control are dropped.
resource claim;
listen: func() -> result<input-subscription, error>;
/// Returns every pointer kind, active or inactive.
pointers: func() -> result<list<pointer>, error>;
/// Claims `control` on `pointer` from the host until the returned handle is
/// dropped.
take-control: func(pointer: pointer-kind, control: control) -> result<claim, error>;
}