Mouse Events
Mouse message listening is different from other message listening; it is a separate Listener. The code is as follows:
let eventListener = new SView.EventListener();
eventListener.mouseDownListener = function(event){
//The listener callback when the mouse is pressed or a touch starts
//If it returns true, the callbacks added afterwards are executed. If all callbacks return true, the mouse-down event in H5 is executed.
//If it returns false, the callbacks added afterwards are no longer executed, and the mouse-down event in H5 is not executed either.
return true;
}
eventListener.mouseMoveListener = function(event){
//The listener callback when the mouse moves or a touch moves
//See mouseDownListener for the return value effect
return true;
}
eventListener.mouseUpListener = function(event){
//The listener callback when the mouse is released or a touch ends
//See mouseDownListener for the return value effect
return true;
}
eventListener.mouseWheelListener = function(event){
//The listener callback when the mouse wheel scrolls
//See mouseDownListener for the return value effect
return true;
}
eventListener.keyDownListener = function(event){
//The listener callback when a keyboard key is pressed
//See mouseDownListener for the return value effect
return true;
}
eventListener.keyUpListener = function(event){
//The listener callback when a keyboard key is released
//See mouseDownListener for the return value effect
return true;
}
frame.addEventListener(eventListener);
The event in the callback functions is an event object encapsulated by H5 itself, divided into M3D.Inputs.MouseEventArgs, M3D.Inputs.TouchEventArgs, and M3D.Inputs.KeyEventArgs; event.inputEventType is the input type, of type M3D.Inputs.InputEventType, with the corresponding values:
M3D.Inputs.InputEventType.INPUTEVENT_MOUSE_DOWN//Mouse down
M3D.Inputs.InputEventType.INPUTEVENT_MOUSE_MOVE//Mouse move
M3D.Inputs.InputEventType.INPUTEVENT_MOUSE_UP//Mouse up
M3D.Inputs.InputEventType.INPUTEVENT_MOUSE_WHEEL//Mouse wheel
M3D.Inputs.InputEventType.INPUTEVENT_TOUCH_DOWN//Touch down
M3D.Inputs.InputEventType.INPUTEVENT_TOUCH_MOVE//Touch move
M3D.Inputs.InputEventType.INPUTEVENT_TOUCH_UP//Touch up
M3D.Inputs.InputEventType.INPUTEVENT_KEY_DOWN//Key down
M3D.Inputs.InputEventType.INPUTEVENT_KEY_UP//Key up
The EventArgs of each event correspond as follows:
MouseEventArgs.mouseButton;//The mouse button, of type M3D.Inputs.MouseButton
MouseEventArgs.deltalScroll;//The mouse middle button scroll value
MouseEventArgs.mouseEvent;//The event corresponding to the mouse event, of type MouseEvent/WheelEvent
M3D.Inputs.MouseButton.MOUSE_BUTTON_NONE//No button
M3D.Inputs.MouseButton.MOUSE_BUTTON_LEFT//Mouse left button
M3D.Inputs.MouseButton.MOUSE_BUTTON_MIDDLE//Mouse middle button
M3D.Inputs.MouseButton.MOUSE_BUTTON_RIGHT//Mouse right button
TouchEventArgs.touchCount;//The number of touch points pressed
TouchEventArgs.touchEvent;//The event corresponding to the touch event, of type TouchEvent
KeyEventArgs.key;//The key value, of type M3D.Inputs.Key
KeyEventArgs.keyEvent;//The event corresponding to the key event, of type KeyboardEvent