Mouse events

Several kinds of mouse events can be generated for the View

Event Constant Description
"mouse-down" MouseDown The mouse button was pressed.
"mouse-up" MouseUp The mouse button has been released.
"mouse-move" MouseMove Mouse cursor moved
"mouse-out" MouseOut The mouse cursor has moved outside the View, or entered the child View
"mouse-over" MouseOver The mouse cursor has moved within the area of View
"click-event" ClickEvent There was a mouse click
"double-click-event" DoubleClickEvent There was a double mouse click
"context-menu-event" ContextMenuEvent The key for calling the context menu (right mouse button) is pressed

The main event data listener has the following format:


func(View, MouseEvent)

where the second argument describes the parameters of the mouse event. The MouseEvent structure has the following fields:
Field Type Description
TimeStamp uint64 The time the event was created (in milliseconds). The starting point depends on the browser implementation (EPOCH, browser launch, etc.).
Button int The number of the mouse button clicked on which triggered the event
Buttons int Bitmask showing which mouse buttons were pressed when the event occurred
X float64 The horizontal position of the mouse relative to the origin View
Y float64 The vertical position of the mouse relative to the origin View
ClientX float64 Horizontal position of the mouse relative to the upper left corner of the application
ClientY float64 The vertical position of the mouse relative to the upper left corner of the application
ScreenX float64 Horizontal position of the mouse relative to the upper left corner of the screen
ScreenY float64 Vertical position of the mouse relative to the upper left corner of the screen
CtrlKey bool The Ctrl key was active when the event occurred.
ShiftKey bool The Shift key was active when the event occurred.
AltKey bool The Alt (Option or ⌥ in OS X) key was active when the event occurred.
MetaKey bool The Meta key (for Mac this is the ⌘ Command key, for Windows is the Windows key ⊞) was active when the event occurred.

Button field can take the following values

Value Constant Description
<0 No buttons pressed
0 PrimaryMouseButton Main button. Usually the left mouse button (can be changed in the OS settings)
1 AuxiliaryMouseButton Auxiliary button (wheel or middle mouse button)
2 SecondaryMouseButton Secondary button. Usually the right mouse button (can be changed in the OS settings)
3 MouseButton4 Fourth mouse button. Usually the browser's Back button
4 MouseButton5 Fifth mouse button. Usually the browser button Forward

The Button field is a bit mask combining (using OR) the following values

Value Constant Description
1 PrimaryMouseMask Main button
2 SecondaryMouseMask Secondary button
4 AuxiliaryMouseMask Auxiliary button
8 MouseMask4 Fourth button
16 MouseMask5 Fifth button

You can also use listeners in the following formats:

  • func(MouseEvent)
  • func(View)
  • func()

You can get lists of listeners for mouse events using the functions:

func GetMouseDownListeners(view View, subviewID ...string) []func(View, MouseEvent)
func GetMouseUpListeners(view View, subviewID ...string) []func(View, MouseEvent)
func GetMouseMoveListeners(view View, subviewID ...string) []func(View, MouseEvent)
func GetMouseOverListeners(view View, subviewID ...string) []func(View, MouseEvent)
func GetMouseOutListeners(view View, subviewID ...string) []func(View, MouseEvent)
func GetClickListeners(view View, subviewID ...string) []func(View, MouseEvent)
func GetDoubleClickListeners(view View, subviewID ...string) []func(View, MouseEvent)
func GetContextMenuListeners(view View, subviewID ...string) []func(View, MouseEvent)