Getting exact millisecond a key is pressed [GameLab]

Hi, is there any way in the GameLab to get the exact millisecond a key was pressed on the keyboard? Currently the best solution we have is to do

if (keyWentDown("A")) { getTime(); }

…However, this will return a seemingly random millisecond within the 16 millisecond window for a frame (assuming 60 frames per second), which is practically no better than just using World.frameCount. We know the AppLab has event listeners which I imagine are more precise. Is there anything similar in the GameLab?

Here is the test program we made to show this (there are no visuals, it’s all in the console): https://studio.code.org/projects/gamelab/eZMhfXlwL_Q2k6PqaVwcybwvfJ_2PufDAsoyOYBE4Lg

Hello @taggerung,
if you are looking for a more precise timing when each key is pressed, May i suggest a builtin listener for any time a key is utilized in any manner. this acts and updates independently from whenever the user decides to use a key
Best of luck!

function keyPressed() {
  if (keyCode === 100) {
    console.log(getTime())
  }
}
1 Like