Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move the mouse in JDK 10? .mousePress(InputEvent.BUTTON1_MASK); doesn't work anymore

Tags:

java

click

mouse

I was trying to position the mouse and simulate a click with Robot but it seems like that is no longer supported in JDK 10. It looks like this and says The field InputEvent.BUTTON1_MASK is deprecated since version 9.

Does anybody know a way to fix this or how to simulate a click in another way?

like image 360
Gustav Avatar asked Oct 30 '25 18:10

Gustav


1 Answers

From its documentation:

However, it is recommended to use InputEvent.BUTTON1_DOWN_MASK, InputEvent.BUTTON2_DOWN_MASK, InputEvent.BUTTON3_DOWN_MASK instead.

So InputEvent.BUTTON1_DOWN_MASK is probably what you're looking for.

I believe the change is partly due to Java now supporting mice with more than three buttons.

Note: Remember to also call mouseRelease to be sure that the click is registered.

like image 188
Jacob G. Avatar answered Nov 02 '25 09:11

Jacob G.