Varrience
the optimal solution is to have a loading screen to calculate all possible player inputs and reactions to those player inputs.
should only take a couple of minutes to load if you optimize it.
Of course, If you're willing to put in a bit of work, you could have a bunch of if(){} statements for each frame and decide what the reaction to the player input should be real-time(instead of pre-loading the reactions)
for example,
if(frameCount === 0){
if(keyDown("left")){
setTimeOut(function(){
if(keyDown("left")){
}else if(keyDown("right")){
}else if(keyDown("up")){
}else if(keyDown("down")){
}
},1);
}else if(keyDown("right")){
setTimeOut(function(){
if(keyDown("left")){
}else if(keyDown("right")){
}else if(keyDown("up")){
}else if(keyDown("down")){
}
},1);
}else if(keyDown("up")){
setTimeOut(function(){
if(keyDown("left")){
}else if(keyDown("right")){
}else if(keyDown("up")){
}else if(keyDown("down")){
}
},1);
}else if(keyDown("down")){
setTimeOut(function(){
if(keyDown("left")){
}else if(keyDown("right")){
}else if(keyDown("up")){
}else if(keyDown("down")){
}
},1);
}
}