Here is basically how I get some "key speed typing data" with JavaScript:
<!DOCTYPE html>
<html>
<body>
<input id="in"></input>
<p id="out">new</p>
<script>
var downlast = 0;
document.getElementById("in").onkeydown = function () {
var downlast2 = new Date().getTime();
document.getElementById("out").innerHTML += ","+(downlast2-downlast);
downlast = downlast2;
};
</script>
</body>
</html>
But, at times the CPU is busy, delaying event triggers, causing errors of even more than 50ms. So, is there a way to modify this script to catch and void most of these outliers? I hoped to find minimum/maximum bounds on the key press times, but this now seems impossible with JavaScript's event-driven methods (i.e., instead of events, I'd prefer to have a function to check if a key is currently pressed).
Most generally, I am looking for any solution which will work in a Chrome browser, so I don't actually need to stick with Javascript. How can I collect typing data with more confidence if I can't control how busy the client's CPU is?
because all execution in javascript is scheduled on an event loop, it can’t get you accurate measurements of how long between the user presses buttons, since those signals have to get scheduled between whatever other javascript is running on the page.
I don’t have a recommendation for how to do this in the browser.