java examples
Home Java Examples Resources Java Interview Questions
Brainpower SEO

How to get mouse number of buttons?

MouseInfo provides methods for getting information about the mouse, such as mouse pointer location and the number of mouse buttons.

package com.javacoderanch.example.awt;

import java.awt.*;

public class MouseNumberOfButtons {
    public static void main(String[] args) {
        //
        // Get the number of buttons on the mouse. On systems without a
        // mouse, returns -1. HeadlessException if
        // GraphicsEnvironment.isHeadless() returns true
        //
        int numberOfButtons = MouseInfo.getNumberOfButtons();
        System.out.println("Mouse Number Of Buttons = " + numberOfButtons);
    }
}