Created
January 19, 2014 01:42
-
-
Save jcblw/8499352 to your computer and use it in GitHub Desktop.
Pattern Matching Pressed Keys
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 INPUTS = [0,0,0,0,0]; | |
function loop ( ) { | |
var pressed = [], | |
released = [], | |
keys; | |
for ( var i = 0; i < INPUTS.length; i += 1 ) { | |
// parsey stuff | |
if ( INPUTS[ i ] ) { | |
pressed.push(i) | |
}else { | |
released.push(i); | |
} | |
} | |
keys = Object.keys( pressed ); | |
if ( !!~pressed.indexOf(4) && keys.length === 2 ) { | |
if ( !!~pressed.indexOf(2) ) { | |
console.log( "two keys press", pressed, released) | |
} | |
return | |
} | |
console.log( pressed, released ); | |
}; | |
loop(); | |
INPUTS = [0,1,1,0,1]; | |
loop(); | |
INPUTS = [0,0,1,0,1]; | |
loop(); | |
INPUTS = [1,0,0,0,0]; | |
loop(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment