aframevr / aframe-inspector

:mag: Visual inspector tool for A-Frame. Hit *<ctrl> + <alt> + i* on any A-Frame scene.
https://aframe.io/aframe-inspector/examples/
MIT License
655 stars 203 forks source link

Inject Inspector shortcut is not friendly to international keyboard configurations #583

Closed tiagosomda closed 1 year ago

tiagosomda commented 5 years ago

Note: when I say "international keyboard layouts" I mean keyboards that are firing an Input Method Editor event (composing a key) when pressing the key combination ctrl + alt + i

Some International keyboard layouts when given the key combination ctrl + alt + i will fire an event that is not recognized by the current code in aframe inspector.

code reference: src/index.js line 180

In an international keyboard,
when the 'i' key is pressed, the event has the values:

This makes the current check fail :
var shortcutPressed = evt.keyCode === 73 && evt.ctrlKey && evt.altKey;

Thus, to be more friendly to those types of keyboard layouts,
I believe that we should change the code to handle this edge case.

here is a proposed solution:

...
  _this3.toggleShortcutStarted = false
  window.addEventListener('keydown', function (evt) {
    // Alt + Ctrl + i: Shorcut to toggle the inspector
    if (_this3.toggleShortcutStarted === false && evt.ctrlKey && evt.altKey) {
      _this3.toggleShortcutStarted = true;
    } else if (_this3.toggleShortcutStarted === true && evt.keyCode === 73) {
      _this3.toggleShortcutStarted = false;
      _this3.toggle();
    }
  });
...

There is probably a more suitable place for the toggleShortcutStarted value.
I just used _this3 as an example.

Adding @dmarcos who I saw that was answering people about this issue on slack.

vincentfretin commented 1 year ago

I think this is fixed by #658 you can probably close @dmarcos

dmarcos commented 1 year ago

Fixed by https://github.com/aframevr/aframe-inspector/pull/658