I am aware of the MouseInfo.getPointerInfo() method, but you can only get the mouse location using this. However, I also want to know the buttons pressed (specifically just the BUTTON1_DOWN_MASK), without any events. This is because the program will ask the user to create a rectangle by dragging the mouse on the screen with animations that is not part of the java application. Thank you for your help.

SwingUtilities implements (only for mouse with three Buttons, for example there are Mouse with 5Buttons, then rest of Buttons are ignored by default)

isLeftMouseButton
isMiddleMouseButton
isRightMouseButton

It is kind of hard to get mouse event without events since the event is an event in its nature. Do you want to have like a while loop where you call a method getMouseInfo() that return the state of the mouse? An Event is just a callback method that is called when something happens in some other part of the program.

What you can do to catch all mouse events without having a component listening to events is to add an AWTEventListener. This listens to all AWT events and it is possible to mask what event to listen to if you only are interested in mouse events.

Toolkit.getDefaultToolkit().addAWTEventListener(theListener, AWTEvent.MOUSE_MOTION_EVENT_MASK + AWTEvent.MOUSE_EVENT_MASK);

Google AwtEventListener.

Neither of those work because they are still dealing with events...Or can you show me how to use it that way?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.