Class MouseEvent

java.lang.Object
org.jline.terminal.MouseEvent

public class MouseEvent extends Object
Represents a mouse event in a terminal that supports mouse tracking.

The MouseEvent class encapsulates information about mouse actions in a terminal, including the type of event (press, release, move, etc.), which button was involved, any modifier keys that were pressed, and the coordinates where the event occurred.

Mouse events are only available in terminals that support mouse tracking, which can be enabled using Terminal.trackMouse(Terminal.MouseTracking). Once mouse tracking is enabled, mouse events can be read using Terminal.readMouseEvent().

Mouse events include:

  • Pressed - A mouse button was pressed
  • Released - A mouse button was released
  • Moved - The mouse was moved without any buttons pressed
  • Dragged - The mouse was moved with a button pressed
  • Wheel - The mouse wheel was scrolled

Example usage:

 Terminal terminal = TerminalBuilder.terminal();

 // Enable mouse tracking
 if (terminal.hasMouseSupport()) {
     terminal.trackMouse(Terminal.MouseTracking.Normal);

     // Read mouse events
     MouseEvent event = terminal.readMouseEvent();
     System.out.println("Mouse event: type=" + event.getType() +
                        ", button=" + event.getButton() +
                        ", position=" + event.getX() + "," + event.getY());
 }
 
See Also:
  • Constructor Details

    • MouseEvent

      public MouseEvent(MouseEvent.Type type, MouseEvent.Button button, EnumSet<MouseEvent.Modifier> modifiers, int x, int y)
      Creates a new MouseEvent with the specified parameters.
      Parameters:
      type - the type of mouse event (press, release, etc.)
      button - the button involved in the event
      modifiers - the modifier keys pressed during the event
      x - the column (horizontal) position of the event
      y - the row (vertical) position of the event
  • Method Details

    • getType

      public MouseEvent.Type getType()
      Returns the type of this mouse event.
      Returns:
      the event type (press, release, move, etc.)
    • getButton

      public MouseEvent.Button getButton()
      Returns the button involved in this mouse event.
      Returns:
      the mouse button
    • getModifiers

      public EnumSet<MouseEvent.Modifier> getModifiers()
      Returns the set of modifier keys pressed during this mouse event.
      Returns:
      the set of modifier keys (Shift, Alt, Control)
    • getX

      public int getX()
      Returns the column (horizontal) position of this mouse event.
      Returns:
      the X coordinate (column)
    • getY

      public int getY()
      Returns the row (vertical) position of this mouse event.
      Returns:
      the Y coordinate (row)
    • toString

      public String toString()
      Returns a string representation of this MouseEvent object.

      The string representation includes all properties of the mouse event: the event type, button, modifier keys, and coordinates.

      Example output:

       MouseEvent[type=Pressed, button=Button1, modifiers=[Shift], x=10, y=20]
       
      Overrides:
      toString in class Object
      Returns:
      a string representation of this object