I would simply add the pressed keys to a string and compare it with your password. if a wrong key is pressed the string is cleared and you start from the beginning.

function checkkey(letter){
keystrokes+=letter
if (magicword.substr(0,keystrokes.length)!=keystrokes ){
keystrokes=""
} else {
if (magicword==keystrokes)
opensesame()
}
}

This function assumes that "letter" already contains the keycode converted to a letter.

Cheers
Mario