2808 explained code solutions for 75 technologies


chrome-extensionHow to simulate keypress/keyup/keydown event on a page


document.querySelector('input')
.dispatchEvent(new KeyboardEvent('keypress', {'key': 'a'}));ctrl + c
'input'

query selector for an element to simulate keypress on

dispatchEvent

triggers specified event

KeyboardEvent

creates specified key event

keypress

we want to simulate keyup event

'key': 'a'

simulate a key press (all keys list)