@@ -453,11 +453,11 @@ function updateOverlap(now: number): void {
453453}
454454
455455function carryoverFirstKeypress (
456- lastKey : string ,
456+ lastKey : string | undefined ,
457457 lastKeyData : Keydata | undefined ,
458458) : void {
459459 // Carry over
460- if ( lastKeyData !== undefined ) {
460+ if ( lastKey !== undefined && lastKeyData !== undefined ) {
461461 keypressTimings = {
462462 spacing : {
463463 first : lastKeyData . timestamp ,
@@ -477,19 +477,24 @@ function carryoverFirstKeypress(
477477}
478478
479479export function resetKeypressTimings ( carryover : boolean ) : void {
480- // Because keydown triggers before input, we need to grab the first keypress data here and carry it over
481-
482- // Take the key with the largest index
483- const lastKey = Object . keys ( keyDownData ) . reduce ( ( a , b ) => {
484- const aIndex = keyDownData [ a ] ?. index ;
485- const bIndex = keyDownData [ b ] ?. index ;
486- if ( aIndex === undefined ) return b ;
487- if ( bIndex === undefined ) return a ;
488- return aIndex > bIndex ? a : b ;
489- } , "" ) ;
490-
491- // Get the data
492- const lastKeyData = keyDownData [ lastKey ] ;
480+ let lastKey ;
481+ let lastKeyData ;
482+
483+ if ( carryover ) {
484+ // Because keydown triggers before input, we need to grab the first keypress data here and carry it over
485+
486+ // Take the key with the largest index
487+ lastKey = Object . keys ( keyDownData ) . reduce ( ( a , b ) => {
488+ const aIndex = keyDownData [ a ] ?. index ;
489+ const bIndex = keyDownData [ b ] ?. index ;
490+ if ( aIndex === undefined ) return b ;
491+ if ( bIndex === undefined ) return a ;
492+ return aIndex > bIndex ? a : b ;
493+ } , "" ) ;
494+
495+ // Get the data
496+ lastKeyData = keyDownData [ lastKey ] ;
497+ }
493498
494499 keypressTimings = {
495500 spacing : {
0 commit comments