Skip to content
pepijndevos edited this page Sep 13, 2010 · 2 revisions

This one is very simple to figure out yourself once you discover java.awt.Robot

We just include a bunch of java packages:

from java.awt import Robot, Toolkit
from java.awt.event import InputEvent
from java.awt.MouseInfo import getPointerInfo

This time buttons are not just 1 2 and 3 but

InputEvent.BUTTON1_MASK
InputEvent.BUTTON3_MASK
InputEvent.BUTTON2_MASK

The rest is a piece of cake:

r = Robot()
r.mouseMove(x, y)
r.mousePress(button)
r.mouseRelease(button)

Java means getters and setter, and that is what we’ll use for the next 2 steps:

loc = getPointerInfo().getLocation()
loc.getX
loc.getY
dim = Toolkit.getDefaultToolkit().getScreenSize()
dim.getWidth()
dim.getHeight()
Clone this wiki locally