Created
April 10, 2015 15:23
-
-
Save catc/c4cbbc9b12d2e875ac0e to your computer and use it in GitHub Desktop.
secret code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var keysPressed = [], | |
keyTimer | |
var verifiedKeys = [74,65,80,65,78].toString() | |
$(window).on('keydown', function(e){ | |
if (e.keyCode >= 65 && event.keyCode <=90){ | |
clearTimeout(keyTimer) | |
keysPressed.push( e.keyCode ) | |
keyTimer = setTimeout(verifyCode, 1500) | |
} | |
}) | |
function verifyCode(){ | |
if ( keysPressed.length >= 5){ | |
if ( keysPressed.toString().indexOf(verifiedKeys) > -1 ){ | |
// correct keys pressed, do whatever | |
$(window).off('keydown') | |
} else { | |
// incorrect keys pressed, reset keyspressed | |
keysPressed = [] | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment