Skip to content

rafapaezbas/piano-keyboard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Piano keyboard

Web component canvas based piano keyboard.

piano-keyboard

Example

<html>
  <body>
    <piano-keyboard height="100" width="800" octaves="5"></piano-keyboard>
  </body>
  <script src="https://cdn.jsdelivr.net/gh/rafapaezbas/piano-keyboard/piano-keyboard.js"></script>
  <script>
    document.querySelector('piano-keyboard').addEventListener('key-pressed', ({ detail }) => {
      console.log(detail.note)
    })
  </script>
  <style>
    piano-keyboard {
      display: block;
      text-align: center;
    }
  </style>
</html>

Attributes

width

Set the width in pixels of the piano keyboard canvas (default 600).

height

Set the height in pixels of the piano keyboard canvas (default 100).

octaves

Set the number of octaves in the keyboard (default 3).

Events

piano-keyboard.on('key-pressed', (event) => {})

event.detail.note contains the pressed note (english notation).

API

piano-keyboard.draw(pressedKeys = [])

Redraws the keyboard with pressedKeys highlighted in red.

About

Web component canvas based piano keyboard

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published