Notices

Great community. Great ideas.

Welcome to ASP/Free, a community dedicated to helping beginners and professionals alike in improving their knowledge of Microsoft's development and administration technologies. Sign up today to gain access to the combined insight of tens of thousands of members.

Thread: Simulate live typing

Results 1 to 2 of 2
Share This Thread →
  1. #1
    riouxr is offline Registered User
    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

    Simulate live typing

    I need to simulate someone typing in fields on a fake webpage. You see this in movies all the time. Someone types whatever on the keyboard but the right text appears in a field. This avoids having to reshoot over and over in case the actor can't properly type or makes mistakes.

    In my case I have a few fields on the webpage, like fist name, last name, email (simple fields) and a comment box (text field). This is actually for a movie. The actor is having a chat session. I saw examples where the text appears letter by letters automatically at a stable rhythm but that's not what I'm looking for. The text need to appear as the actor types on the keyboard, letter by letter. Any idea? Thanks.

  2. #2
    riouxr is offline Registered User
    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0
    Here's a solution if anyone needs the same thing. Enjoy!

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html xmlns="">
    <head>
    <title>Fake Input</title>
    </head>

    <body>

    Hi my friends: <input type="text" fake-input="Hi my friends"/>
    <br>
    Another one!: <input type="text" fake-input="Another one!"/>
    <br>
    Normal : <input type="text" size="40">
    <br>
    Username : <input type="text" fake-input="PizzaGuy"/>
    <br>
    Password : <input type="password" fake-input="notseen"/>



    <script type="text/javascript">

    // Bound to a keydown event of a text input tag, replaces
    // the keystroke with the next character in the 'fake-input' attribute
    function fakein(evt)
    {
    console.log(evt)
    evt = evt || window.event; // IE bug
    var charcode = evt.keyCode || evt.which;
    if (charcode < 48 || charcode > 90) {
    return true;
    }

    targ = evt.target || evt.srcElement;
    if (targ.nodeType == 3) targ = targ.parentNode; // safari bug

    fake_input = targ.attributes['fake-input'].value;
    current = targ.value;
    console.log(fake_input)
    console.log(current)
    targ.value = fake_input.substr(0,current.length+1);

    return false;
    }

    // Find all input tags with fake-input and bind the fakein function
    inputs = document.getElementsByTagName('input');
    for (var i=0;i < inputs.length; i++) {
    myinput = inputs[i];
    if (myinput.attributes['fake-input']) {
    myinput.onkeydown = fakein
    }
    }
    </script>

    </body>
    </html>

Share This Thread →

Become Part of This Conversation

Join NowFor Free!

Similar Threads

  1. How to simulate?
    By Craigt in forum HTML, JavaScript And CSS Help
    Replies: 2
    Last Post: April 20th, 2011, 07:05 AM
  2. OSU scientists simulate tsunami's impact (AP)
    By RSS_News_User in forum Science News
    Replies: 0
    Last Post: September 14th, 2007, 07:04 PM
  3. Scientists to simulate voyage to Mars (AP)
    By RSS_News_User in forum Science News
    Replies: 0
    Last Post: July 11th, 2007, 05:04 PM
  4. Scientists to simulate voyage to Mars (AP)
    By RSS_News_User in forum Science News
    Replies: 0
    Last Post: July 11th, 2007, 04:04 PM
  5. Scientists to Simulate NYC Gas Attack (AP)
    By RSS_News_User in forum Science News
    Replies: 0
    Last Post: August 5th, 2005, 06:02 PM

ASP Free Advertisers and Affiliates