Skip to content

AbstractKeyAccumulator

Overview

base type for an object that accumulates key presses, works in conjunction with the common-code keypad

@author John Blanco @author Aadish Gupta

Class AbstractKeyAccumulator

import { AbstractKeyAccumulator } from 'scenerystack/scenery-phet';

Constructor

new AbstractKeyAccumulator( validators : ( ( keys: KeyIDValue[] ) => boolean )[] )

Instance Methods

clear()

Clears the accumulated keys.

setClearOnNextKeyPress( clearOnNextKeyPress : boolean )

Sets/clears the flag that determines whether pressing a key (except for backspace) will clear the accumulated keys.

getClearOnNextKeyPress() : boolean

Gets the value of the flag determines whether pressing a key (except for backspace) will clear the accumulated keys.

validateKeys( proposedKeys : KeyIDValue[] ) : boolean

(protected)

validates a proposed set of keys and (if valid) update the property that represents the accumulated keys @param proposedKeys - the proposed set of keys, to be validated

@returns boolean

updateKeys( proposedKeys : KeyIDValue[] )

(protected)

update the property that represents the accumulated keys @param proposedKeys - the proposed set of keys

handleKeyPressed( keyIdentifier : KeyIDValue )

Called by the key accumulator when this key is pressed.

handleClearOnNextKeyPress( keyIdentifier : KeyIDValue ) : KeyIDValue[]

(protected)

creates an empty array if clearOnNextKeyPress is true, the behavior differs if Backspace key is pressed

dispose()

Instance Properties

stringProperty : ReadOnlyProperty<string>

(readonly)

string representation of the keys entered by the user

valueProperty : ReadOnlyProperty<number | null>

(readonly)

numerical value of the keys entered by the user

accumulatedKeysProperty : Property<KeyIDValue[]>

(readonly)

Property that tracks the accumulated key presses as an array

Source Code

See the source for AbstractKeyAccumulator.ts in the scenery-phet repository.