Open justinkim668 opened 2 years ago
I already added an an addEventListener function in the init.js file to track the spacebar, but for some reason it's still not working @santolucito. I am trying to figure out why this is not working.
playButton.addEventListener('keyup', event => { if (event.key === ' ' && event.target === document.body) { event.preventDefault(); recordedAudio.play() console.log('Space pressed') } });
changed playButton.addEventListener to document.addEventListener. The issue here is that it tracks spacebar pressing across the entire webpage, which creates issues when the spacebar is being used in other parts of the interface (i.e. we do not want the beat to play every time the spacebar is used to type code in the live coding interface). Hence we need to figure out a way to filter out non-relevant instances of the spacebar.
@justinkim668 did you ever finish this?
if not, you probably want the .hasFocus() function from codeMirror (https://codemirror.net/doc/manual.html) to tell you if the user's cursor is in the code window. if so, do not start or stop the music on a spacebar press.
any updates @justinkim668 ?