Skip to content

Instantly share code, notes, and snippets.

@ahomu
Created May 24, 2012 03:57
Show Gist options
  • Save ahomu/2779343 to your computer and use it in GitHub Desktop.
Save ahomu/2779343 to your computer and use it in GitHub Desktop.
コナミコマンド
$(document).bind('keydown', detectKonamiCommand);
var konamiTimer,
konamiLog = [],
keyMap = {
37: '←',
38: '↑',
39: '→',
40: '↓',
65: 'A',
66: 'B'
};
function detectKonamiCommand(e) {
clearTimeout(konamiTimer);
konamiLog.push(keyMap[e.keyCode]);
if (konamiLog.join('').indexOf('↑↑↓↓←→←→BA') !== -1) {
console.log('konami!!!!!!!!!!!!!');
konamiLog = [];
}
konamiTimer = setTimeout(function() {
console.log('clear');
konamiLog = [];
}, 800);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment