I have the following:
<textarea id="text"></textarea>
<textarea id="simulator"></textarea>
<br/>
<div onclick="simulate()">Simulate</div>
keyslog = [];
$('#text').bind('keyup keydown keypress mousedown mouseup', function(e){
keyslog.push(e);
}
function simulate(){
for(var i=0;i<keyslog.length;i++){
var e = keyslog[i];
// how to fire "e" event again on #simulator?
}
}
My failed attempts were:
document.getElementById('simulator').dispatchEvent(e);
And
$('#simulator').trigger(e);
The question is how to trigger an event based on an already stored event object. It can be a Mouse or Keyboard event.
P.S. The example is about running a playback of pressed keys with the support of cursor changing/highlighting using mouse.
I think I got this close to what you wanted. Test it on jsbin here: http://jsbin.com/epaqej/18
or copy the code:
JavaScript code:
HTML code: