Skip to content

Commit

Permalink
fix(StateControl): use uncaught key event
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyGlt authored and Desplandis committed Jan 23, 2024
1 parent 9761d58 commit 93bc087
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/Controls/StateControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,24 +324,33 @@ class StateControl extends THREE.EventDispatcher {
viewCoords.copy(this._view.eventToViewCoords(event));

switch (event.pointerType) {
case 'mouse':
case 'mouse': {
this._currentMousePressed = event.button;

let clickKeyPressed = this._currentKeyPressed;

if (clickKeyPressed === undefined) {
if (event.ctrlKey) {
clickKeyPressed = CONTROL_KEYS.CTRL;
} else if (event.shiftKey) {
clickKeyPressed = CONTROL_KEYS.SHIFT;
}
}
this.currentState = this.inputToState(
this._currentMousePressed,
this._currentKeyPressed,
clickKeyPressed,
// Detect if the mouse button was pressed less than 500 ms before, and if the cursor has not moved two much
// since previous click. If so, set dblclick to true.
event.timeStamp - this._clickTimeStamp < 500
&& this._lastMousePressed.button === this._currentMousePressed
&& this._lastMousePressed.viewCoords.distanceTo(viewCoords) < 5,
&& this._lastMousePressed.button === this._currentMousePressed
&& this._lastMousePressed.viewCoords.distanceTo(viewCoords) < 5,
);

this._clickTimeStamp = event.timeStamp;
this._lastMousePressed.button = this._currentMousePressed;
this._lastMousePressed.viewCoords.copy(viewCoords);

break;
}
// TODO : add touch event management
default:
}
Expand Down

0 comments on commit 93bc087

Please sign in to comment.