views:

37

answers:

1

There is a slight pause after any first keypress. Here's the log:

[00.000ms] keypress   -- first keypress
[496.00ms] keypress   -- second keypress after 496 ms
[39.000ms] keypress   -- every other keypress after about 20-40 ms.
[41.000ms] keypress
[21.000ms] keypress
[39.000ms] keypress
...

So there's a pause of half a second after a first keypress, the rest is fired after 20-40 ms.

This is the code to grab the keypresses:

// If we're using the webkit engine, capture the keydowns
if(navigator.userAgent.indexOf("WebKit") != -1){
    window.onkeydown = onKeyPress;
} else{
    // If we're using gecko, capture the keypress
    if(navigator.userAgent.indexOf("Gecko") != -1){
        window.onkeypress = onKeyPress;
    }
}

The first thing the onKeyPress function performs is a debug output (the one from the log above)

Does anyone know why the pause is there? It's like that on Windows or Linux; Firefox or Chrome.

A: 

I think "real games" have access to something much lower live, while Javascript is bound by the OS's auto repeating keypresses limit.

The way I solved it was to create a workaround with onKeyDown and onKeyUp:

So when an onKeyDown event was fired keep on repeating that process until the onKeyUp event is fired.

skerit