Selkies

lib/hardware-keyboard

Whether a touch device has a keyboard attached, told from its pointer and the keys it types.

The dashboards' on-screen keyboard button does nothing on a tablet with a keyboard attached, since the system keeps its on-screen keyboard down then, so the button goes once one is in use. No web API says a keyboard is there, but its keys do: an on-screen keyboard has no Escape, Tab, arrows, function or editing keys, and no Control, Alt or Command to chord with, where every keyboard has them. Letters are no evidence: an engine may report an on-screen key with the code of the key it stands for. So the first of those keys, or a chord, says a keyboard is attached; the verdict lasts while such keys keep coming, and a touch after HARDWARE_KEYBOARD_IDLE_MS without one takes it back, so a keyboard detached mid-session leaves the on-screen one reachable again.

A convertible says it at once where the engine follows its posture. Windows leaves its tablet posture when a Surface's keyboard is attached, and Edge turns the primary pointer from coarse to fine with the touchpad that comes with it, and back when the keyboard is detached (Edge 154 on a Surface Pro 8, within 0.1 s both ways). So on a touch screen a fine primary pointer, at load or on a change, says a keyboard is attached until the pointer turns coarse again, keys or no keys.

Variables

HARDWARE_KEYBOARD_IDLE_MS

const HARDWARE_KEYBOARD_IDLE_MS: number;

Defined in: lib/hardware-keyboard.js:34

How long after its last key an attached keyboard stops being assumed, on the next touch.

Functions

isKeyboardOnlyKeystroke()

function isKeyboardOnlyKeystroke(event): boolean;

Defined in: lib/hardware-keyboard.js:46

Whether a keydown came from a physical keyboard: one of the keys an on-screen keyboard lacks, or any key chorded with Control, Alt or Command.

Parameters

ParameterTypeDescription
eventKeyboardEvent-

Returns

boolean


createHardwareKeyboardWatch()

function createHardwareKeyboardWatch(options?): object;

Defined in: lib/hardware-keyboard.js:58

A store of the verdict, fed keydowns, touches and the primary pointer.

Parameters

ParameterTypeDescription
options?{ now?: () => number; idleMs?: number; }-
options.now?() => number-
options.idleMs?number-

Returns

attached
attached: () => boolean;
Returns

boolean

Whether a keyboard is taken to be attached.

onKeyDown()
onKeyDown(event): void;
Parameters
ParameterTypeDescription
eventKeyboardEvent-
Returns

void

onTouch()
onTouch(): void;
Returns

void

onPointer()
onPointer(fine): void;

The primary pointer of a touch screen turned fine, a keyboard attached with its touchpad, or coarse, the keyboard gone with the keys it typed.

Parameters
ParameterTypeDescription
fineboolean-
Returns

void

reset()
reset(): void;

Forgets the verdict until the next keyboard-only key or pointer change, as when the user asks for the button back.

Returns

void

subscribe()
subscribe(fn): () => void;
Parameters
ParameterTypeDescription
fn(attached) => void-
Returns

Unsubscribes.

() => void


hardwareKeyboard()

function hardwareKeyboard(): object;

Defined in: lib/hardware-keyboard.js:119

The page's watch, listening from its first use: keydowns and touches on the window in the capture phase, before the stream's own handlers take them, and on a touch screen the primary pointer.

Returns

attached
attached: () => boolean;
Returns

boolean

Whether a keyboard is taken to be attached.

onKeyDown()
onKeyDown(event): void;
Parameters
ParameterTypeDescription
eventKeyboardEvent-
Returns

void

onTouch()
onTouch(): void;
Returns

void

onPointer()
onPointer(fine): void;

The primary pointer of a touch screen turned fine, a keyboard attached with its touchpad, or coarse, the keyboard gone with the keys it typed.

Parameters
ParameterTypeDescription
fineboolean-
Returns

void

reset()
reset(): void;

Forgets the verdict until the next keyboard-only key or pointer change, as when the user asks for the button back.

Returns

void

subscribe()
subscribe(fn): () => void;
Parameters
ParameterTypeDescription
fn(attached) => void-
Returns

Unsubscribes.

() => void