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
Static Properties
- EventStreamProvider<KeyEvent> keyDownEvent
-
read / writeAccessor to provide a stream of KeyEvents on the desired target. */
- EventStreamProvider<KeyEvent> keyPressEvent
-
read / writeAccessor to provide a stream of KeyEvents on the desired target. */
- EventStreamProvider<KeyEvent> keyUpEvent
-
read / writeAccessor to provide a stream of KeyEvents on the desired target. */
Properties
- bool altKey
-
read-onlyCaculated value of whether the alt key is pressed is for this event.
- bool bubbles
-
read-only, inherited
- bool cancelable
-
read-only, inherited
- int charCode
-
read-onlyCaculated value of what the estimated charCode is for this event.
- DataTransfer clipboardData
-
read-onlyAccessor to the clipboardData available for this event.
- bool ctrlKey
-
read-onlyTrue if the ctrl key is pressed during this event.
- EventTarget currentTarget
-
read-onlyThe currently registered target for this event.
- bool defaultPrevented
-
read-only, inherited
- int detail
-
read-only
- int eventPhase
-
read-only, inherited
- int keyCode
-
read-onlyCaculated value of what the estimated keyCode is for this event.
- int keyLocation
-
read-onlyAccessor to the part of the keyboard that the key was pressed from (one of KeyLocation.STANDARD, KeyLocation.RIGHT, KeyLocation.LEFT, KeyLocation.NUMPAD, KeyLocation.MOBILE, KeyLocation.JOYSTICK).
- Point layer
-
read-only
- int location
-
read-only
- Element matchingTarget
-
read-only, inheritedA pointer to the element whose CSS selector matched within which an event was fired. If this Event was not associated with any Event delegation, accessing this value will throw an
UnsupportedError
. - bool metaKey
-
read-onlyTrue if the Meta (or Mac command) key is pressed during this event.
- Point page
-
read-only
- List<Node> path
-
read-only, inheritedThis event's path, taking into account shadow DOM.
- bool repeat
-
read-only
- bool shiftKey
-
read-onlyTrue if the shift key was pressed during this event.
- EventTarget target
-
read-only, inherited
- int timeStamp
-
read-only, inherited
- String type
-
read-only, inherited
- Window view
-
read-only
- int which
-
read-onlyCaculated value of what the estimated keyCode is for this event.
- Event wrapped
-
read-only, inherited
Constructors
- 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).
- KeyEvent.wrap(KeyboardEvent parent)
-
Construct a KeyEvent with
parent
as the event we're emulating.
Methods
-
getModifierState(
String keyArgument) → bool -
preventDefault(
) → void -
inherited
-
stopImmediatePropagation(
) → void -
inherited
-
stopPropagation(
) → void -
inherited