import { getDocument } from "./getDocument" ; import { getWindow } from "./getWindow" ; function createKeyboardEvent ( element , type , eventInit = { } ) { if ( typeof KeyboardEvent === "function" ) { return new KeyboardEvent ( type , eventInit ) ; } const event = getDocument ( element ) . createEvent ( "KeyboardEvent" ) ; ( event as any ) . initKeyboardEvent ( type , eventInit . bubbles , eventInit . cancelable , getWindow ( element ) , eventInit . key , eventInit . location , eventInit . ctrlKey , eventInit . altKey , eventInit . shiftKey , eventInit . metaKey ) ; return event ; } example export function fireKeyboardEvent ( element , type , eventInit ) { return element . dispatchEvent ( createKeyboardEvent ( element , type , eventInit ) ) ; }