Forge Viewer 中的鼠标和按键事件

Mouse and key events in Forge Viewer

是否可以在查看器 DOM 元素之外忽略 Forge 查看器中的关键事件?

我有一个单独的 DOM 元素,它有自己的关键事件,但它们不起作用,因为查看器事件适用于整个 DOM (window)。我可以看到鼠标事件和按键事件的处理方式不同,但不明白为什么。

viewer3D.js(第 4.0 版)中的第 13015 - 13026 行:

// If we want to continue listenting to mouse movements outside of the window
  // we need to tie our event listener to the window

  this.domElement.addEventListener( 'mousewheel',     this.mousewheel, false );
  this.domElement.addEventListener( 'DOMMouseScroll', this.mousewheel, false ); // firefox

  //** this.domElement.addEventListener( 'touchstart', function( event ) { _this.touchstart( event )}, false );
  //** this.domElement.addEventListener( 'touchmove', function( event ) { _this.touchmove( event )}, false );

  window.addEventListener( 'keydown', this.keydown, false );
  window.addEventListener( 'keyup',   this.keyup,   false );
  window.addEventListener( 'blur', this.blur, false );

这里的意思应该是好的,如果能改一下就更好了。如果有顺利的解决方法请告诉我,但我被卡住了。

您应该能够注册具有高优先级(例如 1000)的自定义工具,并在所有其他查看器工具之前吸收这些事件。查看 changelog 了解有关 tool.getPriority 的更多详细信息:

// in your custom tool ...
this.handleKeyDown = function(event, keyCode) {

  return true; // absorbed event ...
};

this.getPriority = function() {
   return 1000; // Default is 0, 
   //higher numerical value results in higher priority.
};

还有这篇文章:Creating custom tool