Simply put, this is what you can do:
var memoria = "";
window.onkeyup = function(e) {
letra = String.fromCharCode(e.keyCode); // Capture a letra digitada
memoria += letra; // Adicione no final da memória
memoria = memoria.substr(-5); // Mantenha apenas as 5 ultimas letras
if (memoria == "STACK") {
alert("Parabéns!")
}
}
With each keystroke, get the corresponding letter and store it in a string. When the end of this string matches the password, do something.
Just take care to wipe that memory so it doesn’t grow absurdly. In this example, it is always kept at a maximum of 5 characters, since this is the length of the password.
You could put
memoria = '';
within theif
so Alert fires every time a new word occurrence appears– Renato Gama
@renatoargh Does not shoot, because the next letter typed will change the memory.
– Guilherme Bernal
Oh man, now I get it! + 1
– Renato Gama