KeyboardEvent constructor

KeyboardEvent(
  1. String type, {
  2. Window? view,
  3. bool canBubble = true,
  4. bool cancelable = true,
  5. int? location,
  6. int? keyLocation,
  7. bool ctrlKey = false,
  8. bool altKey = false,
  9. bool shiftKey = false,
  10. bool metaKey = false,
})

Programmatically create a KeyboardEvent.

Due to browser differences, keyCode, charCode, or keyIdentifier values cannot be specified in this base level constructor. This constructor enables the user to programmatically create and dispatch a KeyboardEvent, but it will not contain any particular key content. For programmatically creating keyboard events with specific key value contents, see the custom Event KeyEvent.

Implementation

factory KeyboardEvent(
  String type, {
  Window? view,
  bool canBubble = true,
  bool cancelable = true,
  int? location,
  int? keyLocation, // Legacy alias for location
  bool ctrlKey = false,
  bool altKey = false,
  bool shiftKey = false,
  bool metaKey = false,
}) {
  if (view == null) {
    view = window;
  }
  location ??= keyLocation ?? 1;
  KeyboardEvent e = document._createEvent("KeyboardEvent") as KeyboardEvent;
  e._initKeyboardEvent(
    type,
    canBubble,
    cancelable,
    view,
    "",
    location,
    ctrlKey,
    altKey,
    shiftKey,
    metaKey,
  );
  return e;
}