They both trigger a color change in the cube. However, when I edit the input parameter in the GUI, keydown events also result in a color change, and I would like to avoid that. I am guessing this is because I am using document.addEventListener. However, if I use renderer.domElement.addEventListener instead it wont work.
How can I avoid keydown events to propagate when editing GUI parameters?
I have tried with this and it works just fine, but not sure it is the right approach:
function changeColor(event) {
// Ignore key event when editing dat.GUI input values
if (event.target.localName == "input") {
return;
}
// [...]
}
@rrrr_rrrr Sorry, I probably did not explain myself well.
The issue is when editing the input parameter in the GUI (i.e.: when you use SUPR, or Backspace, or any number to fill the parameter value). Those keydown events get propagated to the 3D scene as well, instead of being stopped at the GUI.
The working solution is when those keydown events are constrained to the GUI.
The pointer event handler is probably not needed for this example. Was just to show the difference in the DOM element (renderer for the pointer and document for the keys). In case I was doing something wrong.