0

How can I simulate pressing a specific key on the document?

Important: without jQuery

With jQuery:

var e = $.Event('keydown');
e.which = 65;
document.trigger(e);

But how can I do this without jquery ?

Falci
  • 1,823
  • 4
  • 29
  • 54

1 Answers1

0

Use 'addEventListener' to capture this action

document.addEventListener('keydown',keydownfunction,false);

function keydownfunction(event){
// this function triggers on any keydown
}
RashFlash
  • 992
  • 2
  • 20
  • 40