0

I'm currently working on a website which would work somewhat like this one:

http://www.keyhero.com/free-typing-test/

I'd like to build a timer which starts on the user's first key press, and ends when the user presses 'Enter'. When the timer ends, I'd want to get the resulting time and push it off to the backend (Django for me) where the WPM will be calculated. However, I have no idea how to get started on this, as I have little experience with jQuery and Javascript and haven't been able to find useful pages.

So my question is, how would I do this? I can post some of my Django files if a better picture of what I am asking is needed.

2
  • 1
    Shouldn't be very hard, something like this -> jsfiddle.net/d8c4z300 Commented Dec 31, 2014 at 21:00
  • Thanks! How do I actually go about pushing the time to the backend? Commented Dec 31, 2014 at 21:10

2 Answers 2

1

You manage the key events with .keypress() for know when the person click in the keyboard. http://api.jquery.com/keypress/

And for key = "ENTER", you just need to validate if is equal to key 13

$('#id_tag').keypress(function (e) {
 var key = e.which;
 if(key == 13)  // the enter key code
  {
    alert("Clicked on enter");
    return false;  
  }
});

I see that post too, that are using keyup(): JQuery Event for user pressing enter in a textbox?

Sign up to request clarification or add additional context in comments.

Comments

1

Well you're going to have to capture the keypress/keydown/keyup event in a jQuery event, then start a setInterval and have that function increment a counter variable of sorts. Then you just reference that variable whenever you want to see how many seconds have passed. A crude example would be:

window.secondsSinceTyped = 0;

$('#textbox').one('keypress', function (e) {
    window.setInterval(function () {
        window.secondsSinceTyped++;
    }, 1000);
});

Then just reference the variable secondsSinceTyped whenever you want to check the time. Note that I used the jquery one binding which will only bind the event once so that every time you type it doesn't rebind the event.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.