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