0

I'm building a musical piano in javascript that allows people to play using their computer keyboards. I've mapped the notes of a piano to a QWERTY keyboard layout. However, if someone has a different keyboard layout, for example AZERTY the order of the notes is wrong.

Is it possible to get the keypressed position rather than the keycode? I'm not interested in the value of the key, just it's position on the keyboard.

If this is possible the piano would work globally and I wouldn't have to create separate key maps for all different language types.

duffymo
  • 305,152
  • 44
  • 369
  • 561
Luke Femur
  • 2,434
  • 1
  • 12
  • 10
  • Could you get their keyboards format for the browser set language?? – ske57 Nov 08 '15 at 20:48
  • `` – ske57 Nov 08 '15 at 20:48
  • I'm not sure how reliable this is. I just tried your code with my laptop in french mode and it still fired back en-US – Luke Femur Nov 08 '15 at 20:54
  • Yeah the more I was reading up on it, even if the locale was correct, you would still be making an assumption on the keyboard type as they can differ. I think your stuck my friend. :( – ske57 Nov 08 '15 at 20:57
  • http://stackoverflow.com/a/8892715 – ske57 Nov 08 '15 at 21:01

1 Answers1

0

In the future use KeyboardEvent.code

A KeyboardEvent property representing the physical key that was pressed, ignoring the keyboard layout and ignoring whether any modifier keys were active.

https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code

Currently only available in Firefox and Chrome Canary.

Luke Femur
  • 2,434
  • 1
  • 12
  • 10