I have code, which have many divs and while I mousedown them browser play different sounds and stop when I mouseup. I need to emulate this MouseDown function by pressing keybuttons on my keyboard.
$( function() {
var idx = 0,
$letters = $( '.note' );
$letters.each( function( i ) {
$( this ).mouseDown( function() {
var letter = $( this ).text();
if ( alphabetSounds[ letter ] ) {
alphabetSounds[ letter ].play();
}
});
});
$letters.each( function( i ) {
$( this ).mouseUp( function() {
var letter = $( this ).text();
if ( alphabetSounds[ letter ] ) {
alphabetSounds[ letter ].stop();
}
});
});
});
$("body").on("keydown", function(e) {
e.preventDefault();
var $note1 = $(".1c");
var $note2 = $(".1cc");
if(e.keyCode == 90) {
$note1.mouseDown();
}
!!!!Trouble in this part
if(e.keyCode == 88) {
$note2.mouseDown();
}
});
How can I fix it, need your help!