Skip to content

Instantly share code, notes, and snippets.

@sketchpunk
Created April 2, 2025 20:14
Show Gist options
  • Save sketchpunk/2c52e4e158640dc5cb2689335b839df8 to your computer and use it in GitHub Desktop.
Save sketchpunk/2c52e4e158640dc5cb2689335b839df8 to your computer and use it in GitHub Desktop.
Clone and Dispatch Events
// Clone an event then dispatch it to an HTML Element
function dispatchClonedEvent( e: Event, elm:HTMLElement ){
if( e.type.startsWith( 'pointer' ) ){
const evt = e as PointerEvent;
elm.dispatchEvent( new PointerEvent( evt.type, {
bubbles : evt.bubbles,
cancelable : evt.cancelable,
clientX : evt.clientX,
clientY : evt.clientY,
button : evt.button,
ctrlKey : evt.ctrlKey,
shiftKey : evt.shiftKey,
altKey : evt.altKey,
metaKey : evt.metaKey
}));
}else{
console.error( 'Can not dispatch cloned event, event type unknown' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment