KeyEvent class

A custom KeyboardEvent that attempts to eliminate cross-browser inconsistencies, and also provide both keyCode and charCode information for all key events (when such information can be determined).

A custom KeyboardEvent that attempts to eliminate cross-browser inconsistencies, and also provide both keyCode and charCode information for all key events (when such information can be determined).

KeyEvent tries to provide a higher level, more polished keyboard event information on top of the "raw" KeyboardEvent.

The mechanics of using KeyEvents is a little different from the underlying KeyboardEvent. To use KeyEvents, you need to create a stream and then add KeyEvents to the stream, rather than using the EventTarget.dispatchEvent. Here's an example usage:

// Initialize a stream for the KeyEvents:
var stream = KeyEvent.keyPressEvent.forTarget(document.body);
// Start listening to the stream of KeyEvents.
stream.listen((keyEvent) =>
    window.console.log('KeyPress event detected ${keyEvent.charCode}'));
...
// Add a new KeyEvent of someone pressing the 'A' key to the stream so
// listeners can know a KeyEvent happened.
stream.add(new KeyEvent('keypress', keyCode: 65, charCode: 97));

This class is very much a work in progress, and we'd love to get information on how we can make this class work with as many international keyboards as possible. Bugs welcome!

Annotations
  • Experimental()
Implements

Constructors

KeyEvent.wrap(KeyboardEvent parent)
Construct a KeyEvent with parent as the event we're emulating.
KeyEvent(String type, {Window view, bool canBubble: true, bool cancelable: true, int keyCode: 0, int charCode: 0, int keyLocation: 1, bool ctrlKey: false, bool altKey: false, bool shiftKey: false, bool metaKey: false, EventTarget currentTarget})
Programmatically create a new KeyEvent (and KeyboardEvent).

Static Properties

keyDownEvent EventStreamProvider<KeyEvent>
read / write
Accessor to provide a stream of KeyEvents on the desired target.
keyUpEvent EventStreamProvider<KeyEvent>
read / write
Accessor to provide a stream of KeyEvents on the desired target.
keyPressEvent EventStreamProvider<KeyEvent>
read / write
Accessor to provide a stream of KeyEvents on the desired target.

Instance Properties

keyCode int
read-only
charCode int
read-only
altKey bool
read-only
which int
read-only
currentTarget EventTarget
read-only
clipboardData DataTransfer
read-only
ctrlKey bool
read-only
detail int
read-only
keyLocation int
read-only
layer Point
read-only
metaKey bool
read-only
page Point
read-only
shiftKey bool
read-only
view Window
read-only
location int
read-only
repeat bool
read-only
wrapped Event Inherited
read-only
bubbles bool Inherited
read-only
cancelable bool Inherited
read-only
defaultPrevented bool Inherited
read-only
eventPhase int Inherited
read-only
target EventTarget Inherited
read-only
timeStamp int Inherited
read-only
type String Inherited
read-only
matchingTarget Element Inherited
read-only
path List<Node> Inherited
read-only

Instance Methods

getModifierState(String keyArgument) → bool
preventDefault() → void Inherited
stopImmediatePropagation() → void Inherited
stopPropagation() → void Inherited