[Java] Button class not defined - use integer values or Java constants instead

Asked by bevan dequeker

*** workaround ***

If anyone is interested, the integer values are:
Button.LFET = 16
Button.RIGTH = 4
Button.MIDDLE = 8

or

from java.awt.event import InputEvent
for LEFT: InputEvent.BUTTON1_MASK
for MIDDLE: InputEvent.BUTTON2_MASK
for RIGHT: InputEvent.BUTTON3_MASK

---------------------------------------------------------

I need to use
mouseDown(Button.LEFT)
in Java
But I can't find the Button class. Does it exist?

Note: It's working by using the integer values directly (easily visible in Python),

But still curious about the Button class.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Calle Rundgren (c-rundgren) said :
#1

There is a button class in java, but I do not think that is what you are looking for.
You are looking for a class in java who presses tha mouse button, right?

In case you are, check this link out: http://download.oracle.com/javase/1.4.2/docs/api/java/awt/Robot.html#Robot()

It is the java robot class and can be used in order to simulate mouse clicks using java.

For example I have been using this code in order to scroll teh mouse wheel:

 from java.awt import Robot
    robot = Robot()
    robot.mouseWheel(100)

tha button class in java is for creating buttons and then make different task when the buttons is pressed.

Revision history for this message
Best RaiMan (raimund-hocke) said :
#2

no, Button class not defined on Java level.

They map the Python Button constants to

from java.awt.event import InputEvent
   LEFT = InputEvent.BUTTON1_MASK
   MIDDLE = InputEvent.BUTTON2_MASK
   RIGHT = InputEvent.BUTTON3_MASK

which in turn leads to that integer constants.

Revision history for this message
bevan dequeker (bevan-i) said :
#3

Thanks for suggesting the Robot framework.
I'll have a look.

What I need is drag-and-hold.
Great if Robot has it.
Otherwise adding a whole new library just to put names onto integers is a bit overkill, and I'll stick to Sikuli, with:
MouseDown
MouseMove
pause
MouseUp
and use AWT's InputEvent.BUTTON1_MASK, which will future-proof it better than 16 does.

(BTW, it would still be good to have a Button class in the org.sikuli.script package - for consistency/documentation sharing)

Revision history for this message
bevan dequeker (bevan-i) said :
#4

Update:
At a glance, the AWT Robot class doesn't offer anything more.
(actually it looks like Sikuli is built on top of it and is more feature-rich :-) )
So I'm now using InputEvent.BUTTON1_MASK - with my 4-step drag-and-hold. and it works great.

Revision history for this message
bevan dequeker (bevan-i) said :
#5

Thanks RaiMan, that solved my question.