Package org.jline.terminal
Class MouseEvent
java.lang.Object
org.jline.terminal.MouseEvent
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Defines the mouse buttons that can be involved in a mouse event.static enum
Defines the modifier keys that can be pressed during a mouse event.static enum
Defines the types of mouse events that can occur. -
Constructor Summary
ConstructorsConstructorDescriptionMouseEvent
(MouseEvent.Type type, MouseEvent.Button button, EnumSet<MouseEvent.Modifier> modifiers, int x, int y) Creates a new MouseEvent with the specified parameters. -
Method Summary
Modifier and TypeMethodDescriptionReturns the button involved in this mouse event.Returns the set of modifier keys pressed during this mouse event.getType()
Returns the type of this mouse event.int
getX()
Returns the column (horizontal) position of this mouse event.int
getY()
Returns the row (vertical) position of this mouse event.toString()
Returns a string representation of this MouseEvent object.
-
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 eventmodifiers
- the modifier keys pressed during the eventx
- the column (horizontal) position of the eventy
- the row (vertical) position of the event
-
-
Method Details
-
getType
Returns the type of this mouse event.- Returns:
- the event type (press, release, move, etc.)
-
getButton
Returns the button involved in this mouse event.- Returns:
- the mouse button
-
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
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]
-