Last active
October 12, 2015 16:44
-
-
Save archywillhe/e3646a8a25e045e17ce9 to your computer and use it in GitHub Desktop.
when Makey Makey meets Super Looper
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 mapping = { | |
65:81, //a -> q | |
83:87, //s -> w | |
68:69, //d -> e | |
70:82, //f -> r | |
71:84, //g -> t | |
72:89, //h -> y | |
37:85, //arrow left -> u | |
38:73, //arrow up -> i | |
40:79, //arrow down -> o | |
39:80 //arrow right -> p | |
}; | |
$("body").keydown(function(e){ | |
console.log(e.which + " pressed"); | |
for (key in mapping){ | |
if(e.which == key){ | |
var keydown = $.Event('keydown'); | |
keydown.which = mapping[key]; | |
$(this).trigger(keydown); | |
console.log(keydown.which + " is triggered to be pressed"); | |
break; | |
} | |
} | |
}); | |
var buttons = [$("#loop0"),$("#loop3"),$("#loop4"),$("#loop5"),$("#loop6")], | |
a = 0, blocker = $("<div id='blocker'/>"); | |
$("body").append(blocker); | |
blocker.css({width:"100%",height:"100%",position:"fixed",left:"0",top:"0"}); | |
blocker.mousedown(function(e) { | |
if(e.which == 3) { | |
//light click to start looping | |
var b = a - 1; | |
if(b===-1){ | |
b = 4; | |
} | |
buttons[b].trigger("click"); | |
}else{ | |
//left click to change instrument | |
buttons[a].trigger("click"); | |
buttons[a].trigger("click"); | |
a++; | |
if(a===5){ | |
a = 0; | |
} | |
} | |
}); | |
blocker.on('contextmenu', function(e) { | |
return false; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment