dart:html
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).
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!
- Implemented types
-
Constructors
- KeyEvent(String type, { Window view, bool canBubble: true, bool cancelable: true, int keyCode: 0, int charCode: 0, int location: 1, bool ctrlKey: false, bool altKey: false, bool shiftKey: false, bool metaKey: false, EventTarget currentTarget })
factory
- Programmatically create a new KeyEvent (and KeyboardEvent).
- KeyEvent.wrap(KeyboardEvent parent)
- Construct a KeyEvent with
parent
as the event we're emulating.
Properties
- altKey → bool
read-only, override
- Calculated value of whether the alt key is pressed is for this event.
- charCode → int
read-only, override
- Calculated value of what the estimated charCode is for this event.
- code → String
read-only, override
- ctrlKey → bool
read-only, override
- True if the ctrl key is pressed during this event.
- currentTarget → EventTarget
read-only
- The currently registered target for this event.
- detail → int
read-only, override
- isComposed → bool
read-only
- isComposing → bool
read-only, override
- key → String
read-only, override
- keyCode → int
read-only, override
- Calculated value of what the estimated keyCode is for this event.
- location → int
read-only, override
- Accessor 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).
- metaKey → bool
read-only, override
- True if the Meta (or Mac command) key is pressed during this event.
- repeat → bool
read-only, override
- shiftKey → bool
read-only, override
- True if the shift key was pressed during this event.
- sourceCapabilities → InputDeviceCapabilities
final
- view → Window
read-only, override
- which → int
read-only, override
- Calculated value of what the estimated keyCode is for this event.
- bubbles → bool
read-only, inherited
- cancelable → bool
read-only, inherited
- composed → bool
read-only, inherited
- defaultPrevented → bool
read-only, inherited
- eventPhase → int
read-only, inherited
- hashCode → int
read-only, inherited
- The hash code for this object. [...]
- isTrusted → bool
read-only, inherited
- matchingTarget → Element
read-only, inherited
- A 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.
- path → List<Node>
read-only, inherited
- This event's path, taking into account shadow DOM. [...]
- runtimeType → Type
read-only, inherited
- A representation of the runtime type of the object.
- target → EventTarget
read-only, inherited
- timeStamp → double
read-only, inherited
- type → String
read-only, inherited
- wrapped → Event
final, inherited
Methods
- getModifierState(String keyArgument) → bool
override
- composedPath() → List<EventTarget>
inherited
- noSuchMethod(Invocation invocation) → dynamic
inherited
- Invoked when a non-existent method or property is accessed. [...]
- preventDefault() → void
inherited
- stopImmediatePropagation() → void
inherited
- stopPropagation() → void
inherited
- toString() → String
inherited
- Returns a string representation of this object.
Operators
- operator ==(dynamic other) → bool
inherited
- The equality operator. [...]
Static Properties
- canUseDispatchEvent → bool
read-only
- keyDownEvent ↔ 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.
- keyUpEvent ↔ EventStreamProvider<KeyEvent>
read / write
- Accessor to provide a stream of KeyEvents on the desired target.