Konami-js is a tiny JavaScript implementation of the Konami Code, but also monitors any arbitrary keyboard sequence.
↑ ↑ ↓ ↓ ← → ← → B A
Konami.code(…) creates an event handler which you attach to any element you would like:
$(document).on('keyup',
Konami.code(function() {
alert('Congratulations, 30 lives!');
})
);
Alternatively, you can specify a different keyCode sequence to monitor with Konami.sequence(…):
$(document).on('keyup',
Konami.sequence(
65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79, 80,
81, 82, 83,
84, 85, 86,
87, 88, 89, 90,
function() {
alert('Now I know my ABCs.\r'+
Next time won't you sing with me?');
})
);
Copyright © 2012, Stephen M. McKamey