Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to simulate a keypress in javascript

window.addEventListener('keydown', (e) => {
  console.log(e)
})

window.dispatchEvent(new KeyboardEvent('keydown', {
  'key': 'a'
}));
//use --> document.addEventListener('keypress', (event)=>{console.log(event)}) <-- copy the output of the key you want
//and place it (as object) at ...ardEvent('keydown', HERE)...
Source by thewebdev.info #
 
PREVIOUS NEXT
Tagged: #simulate #keypress #javascript
ADD COMMENT
Topic
Name
7+2 =