0

I am working on a students project where a webscript (javascript) logs keystroke events (keydown and keyup). At a later stage it should be possible to detect the identity of a user based on their keystroke behaviour.

My question: How fast can javascript react to user events like keydown or keyup. Is it in the range of a few miliseconds or even more? I don't know exactly how accurate the measurements should be but I guess it should be in the range of a few milliseconds.

I have done a lot of research but I couldn't get it out. I found out that the user-event latency of an operating system is about 100 to 10 nano seconds but I have no idea how long it takes until the user-event reaches my webscript.

Also I found out that Firefox handles javascript user events faster than other browsers, because it fires the event regardless of what the main javascript UI thread is doing. Is there a possibilty to find it out? Maybe an assembler program which logs my keystrokes and running simultaniously the javascript program and then compare the log times. Is something like this possible?

Here is a small snippet of my code:

document.getElementById("myInputField").onkeydown = function(event) {myFunction(event);};

function myFunction(event) {
      keystrokes.push({ 'time': performance.now(),'type':'keyDown','code':event.keyCode});
}

Thank you.

  • To play devil's advocate, why do you need to know how accurate it is? Either way, you will simply have to deal with whatever latency is there as there is nothing you can do to make the browsers more responsive. – James Montagne Nov 11 '15 at 20:05
  • Because I have to know if it makes even sense to do that stuff in javascript. If keystroke patterns differ from each other by only a few milliseconds and javascript can only log the events with an accuracy of about 20ms then it would make no sense... – Dominik Varretta Nov 11 '15 at 20:08
  • 1
    The real question is: why do you need to know how long does it take? And the probably faulty answer to it is: you cant know (too many systems, too many browsers) – Elentriel Nov 11 '15 at 20:08
  • @DominikVarretta Makes sense. I interpreted the "student project" part to mean that the professor mandated the project requirements/technology. My mistake,. – James Montagne Nov 11 '15 at 20:10
  • also, consequent keystrokes should have about the same latency, so i come to think your very question is moot (if i understood it correctly). Typing start time aside, the time difference between keystrokes should be pretty onspot. – Elentriel Nov 11 '15 at 20:14
  • @Elentriel: Not so sure about this. Depends on the frequency of the javascript clock/timer I guess. – Dominik Varretta Nov 11 '15 at 20:20
  • @Dominik Varretta you could try writing a java applet which could ideally have better latency? Although i cant help you with that at all, just food for though – Elentriel Nov 11 '15 at 20:23
  • Due to the single-threaded nature of js, the latency of processing the keystrokes will depend heavily on the complexity and efficiency of your processing code. Key strokes will be queued if you do not finish processing one stroke before the next occurs. – James Montagne Nov 11 '15 at 20:29

0 Answers0