I would like to be able to log the key presses on a specific page, trying to implement an \'Easter egg\' type functionality where when the correct keys are pressed in the co
here's an easy way to require the ctrl key to be held down while the user enters a sequence of characters. a bit easier than some of the responses. in the case below pressing and holding ctrl key while typing "quack" (no quotes) will trigger the alert. hth someone, someday.
var easterEgg = [81, 85, 65, 67, 75]; //quack
var eggLength = easterEgg.length;
var currentPosition = 0;
$(document).keydown(function (e) {
if (e.ctrlKey && e.keyCode == easterEgg[currentPosition]) {
e.preventDefault();
if (++currentPosition == eggLength) {
currentPosition = 0;
alert('oh yeah, right there');
}
} else {
currentPosition = 0;
}
});