KeyboardEvent 构造函数

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}
)

编程创建 KeyboardEvent。

由于浏览器差异,在此基本级构造函数中无法指定 keyCode、charCode 或 keyIdentifier 值。此构造函数允许用户编程创建和分发 KeyboardEvent,但将不包含任何特定键内容。对于需要具有特定键值内容的键盘事件的编程创建,请参阅自定义 Event KeyEvent

实现

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;
}