Forge Viewer中的鼠标和按键事件 [英] Mouse and key events in Forge Viewer
问题描述
是否有可能在查看器DOM元素之外忽略Forge查看器中的关键事件?
Is it possible to neglect the key events in the Forge viewer, outside the viewer DOM element?
我有一个单独的DOM元素,它具有自己的键事件,但是它们不起作用,因为查看器事件适用于整个DOM(窗口).我可以看到鼠标事件和键事件的处理方式不同,但无法理解原因.
I have a separate DOM element with it's own key events, but they don't work, because the viewer events apply to the whole DOM (window). I can see that mouse events and key events are handled differently, but cannot understand why.
viewer3D.js 中的第13015-13026行(v.4.0):
Lines 13015 - 13026 in viewer3D.js (v. 4.0):
// 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 );
这里可能有一个很好的意图,但是如果可以更改它将会非常好.如果有解决方法,请告诉我,但我被困住了.
There is probably a good intension here, but it would be really nice if it could be changed. If there is a smooth workaround please tell me, but I am stuck.
推荐答案
您应该能够注册具有较高优先级(例如1000)的自定义工具,并在所有其他查看器工具之前吸收这些事件.请查看更改日志了解更多详细信息关于 tool.getPriority
:
You should be able to register a custom tool with a high priority (eg. 1000) and absorb those events before all other viewer tools. Take a look at the changelog for more details about 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.
};
另请参阅本文: 查看全文