bbc / peaks.js

JavaScript UI component for interacting with audio waveforms
https://waveform.prototyping.bbc.co.uk
GNU Lesser General Public License v3.0
3.2k stars 279 forks source link

shiftKey or ctrlKey awareness when handling events in player instance #414

Closed sshadmand closed 2 years ago

sshadmand commented 2 years ago

First, thanks for you work on Peaks.js!

I'd like to know if a key (namely ctrlKey or shiftKey) is being pressed when a user interacts with the rendered waveform. I can see information about the timecode is passed (https://github.com/bbc/peaks.js#events) in an event, but can't figure out how to know the event.keyCode. Thank you in advance for any direction you may provide.

chrisn commented 2 years ago

This would require changes to Peaks.js to expose the underlying DOM or Konva event, e.g., in click and dblclick events, etc. It sounds like a reasonable thing to add though.

chrisn commented 2 years ago

I have just created a branch that exposes the MouseEvent so that you can check the key states, for example:

// Before
peaks.on('zoomview.click', function(time) {
  console.log(time);
});

// After
peaks.on('zoomview.click', function(event) {
  console.log(event.time);
  console.log(event.evt.ctrlKey);
  console.log(event.evt.shiftKey);
});

Feedback welcome (see #427 for more details)

chrisn commented 2 years ago

This is now implemented (as described above) in Peaks.js v1.0.0. I'll close this, but please re-open if you need any further help.