Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6820735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:27:36+00:00 2026-05-26T21:27:36+00:00

I have the following: <textarea id=text></textarea> <textarea id=simulator></textarea> <br/> <div onclick=simulate()>Simulate</div> keyslog = [];

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:27:37+00:00Added an answer on May 26, 2026 at 9:27 pm

    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:

    jQuery(function() {
      var keyslog = [], ctime = [], counter = 0, when = [], $simulator = $('#simulator'), $log = $('#log');
      $('#text').bind('keyup keydown keypress mousedown mouseup', function(e){
        when[counter] = Date.now(); // get the current time
        // delay_time is 0 for the first element
        // and the difference between the time past since the last event and the current event otherwise
        e.delay_time = (counter) ? (when[counter] - when[counter-1]) : 0;
        keyslog.push(e);
        counter++;
      });
    
      $('#simulator').bind('keyup keydown keypress mousedown mouseup', function (e) {
        // console.log(e.type + ' called on #simulator');
      });
    
      function simulate(current) {
        var e, text = '', char_code, simtext = '';
        // console.log('executing event ' + current + ' of  ' + keyslog.length);
        if (current < keyslog.length) {
           e = keyslog[current];
           setTimeout(function() {
             char_code = e.which || e.charCode || e.keyCode;
             text += e.type + ' called after ' + e.delay_time + '<br />';
             if (e.type === 'keypress') { 
               simtext += String.fromCharCode(char_code); 
             } else if (e.type === 'mousedown') { 
               $simulator.focus(); 
             } else if (e.type === 'mouseup') { 
               $simulator.blur(); 
             }
             $log.append(text); // write to logger
             $simulator.append(simtext); // add text to textarea if exists
             $simulator.trigger(e); // trigger the event on $simulator
             current += 1; // increase the iterator variable
             simulate(current);
           }, e.delay_time);
        } else {
            $log.append(' == FINISHED == ');
        }
      }
    
      $('#simulate').click(function() {
        simulate(0);
      });
    });
    

    HTML code:

    <!DOCTYPE html>
    <html>
    <head>
    <script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
    <script src="events.js"></script>
    <meta charset=utf-8 />
    <title>JS Bin</title>
    <!--[if IE]>
      <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <style>
      article, aside, figure, footer, header, hgroup, 
      menu, nav, section { display: block; }
      #simulate {
        cursor: pointer; border: 2px solid #CCC; width: 80px; text-align: center;
      }
      #container, #log { float: left;}
      #container { width: 25%; }
      #log { width: 50%; }
    </style>
    </head>
    <body>
      <div id="container">
        <h4>Write your text here:</h4>
        <textarea id="text"></textarea>
        <br/><br />
        <div id="simulate">Simulate:</div>
        <br/>
        <textarea id="simulator"></textarea>
      </div>
      <div id="log">
        <h4>Logger here</h4>
      </div>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following html: <div class=bf_form_row> <label for=findout>Text goes here</label> <textarea class=findOut cols=40
i have the following setup <div class=article-content> <div class='editors' id=mine> <h2>My Text</h2> <textarea name=my_text
I have following html: <div id=note> <textarea id=textid class=textclass>Text</textarea> </div> How can I get
I have the following HTML: <div id=form> <form> <textarea id=text></textarea> <span class=error>select this</span> <span
I have the following HTML code: <div id=summary_form> <textarea class=summary>Please fill in</textarea><br/> <textarea class=summary>Please
I have following code: <div class=question> <span class=text_area> <textarea name=text1 id=response1 rows=3 cols=50/> </span>
If I have the following code, where knockout binds the textarea to Text the
In my function for displaying text in textarea,i have written following lines of code
I have progress.js file which has the following code $('#text_area_input').keyup(function() { var text_area_box =$(this).val();//Get
I have some text area field in my grails application. I got the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.