KeyboardEvent 构造函数
以编程方式创建 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;
}