Back to the Shapespark home page

How to recover key events after event.stopPropagation();

I wrote the code as follows to disabled short keys but I can’t recover the function when I click other elements:

function onKeyDown(event) {
      switch (event.keyCode) {
          /*       case 37: //left arrow btn
                   case 39: //right arrow btn
          */
          case 38: //up arrow btn
          case 40: //down arrow btn
          case 87: // w
          case 83: // s
          case 65: // a
          case 68: // d
          case 33: //page up
          case 34: //page down
          case 69: //q
          case 81: //e
              event.stopPropagation();
              break;
      }
  }

  document.getElementById('east-5floor4').addEventListener('click',function () {
      viewer.switchToView('BL东5F');
      viewer.requestFrame();
      setTimeout(function() {
          viewer.openPopup(BalconyEast_5F,
              {centerHorizontally: true, centerVertically: true});
      }, 2750);
      document.addEventListener('keydown', onKeyDown, true);
  });

Does there have some ways to recover key events after event.stopPropagation() (W : Walk Straight S: Walk Back etc.)?

Do you mean that you would like to disable the keys but only temporarily and then re-enable them again?
Try removing the listener when you would like the keys to start working again, something like:

document.removeEventListener(‘keydown’, onKeyDown, true);

1 Like

It’s very helpful and the problem has solved. Thanks a lot!