lackey classes¶
lackey.Region class¶
-
class
lackey.
Region
(*args)[source]¶ Bases:
object
-
ABORT
= 'ABORT'¶
-
BB
= 211¶
-
CREATE_X_DIRECTION_LEFT
= 0¶
-
CREATE_X_DIRECTION_RIGHT
= 1¶
-
CREATE_Y_DIRECTION_BOTTOM
= 1¶
-
CREATE_Y_DIRECTION_TOP
= 0¶
-
EAST
= 220¶
-
EAST_MID
= 310¶
-
LL
= 210¶
-
MID_BIG
= 'MID_HALF'¶
-
MID_HORIZONTAL
= 'MID_HORZ'¶
-
MID_THIRD
= 311¶
-
MID_VERTICAL
= 'MID_VERT'¶
-
NORTH
= 202¶
-
NORTH_EAST
= 302¶
-
NORTH_MID
= 301¶
-
NORTH_WEST
= 300¶
-
PROMPT
= 'PROMPT'¶
-
RETRY
= 'RETRY'¶
-
RR
= 201¶
-
SKIP
= 'SKIP'¶
-
SOUTH
= 212¶
-
SOUTH_EAST
= 322¶
-
SOUTH_MID
= 321¶
-
SOUTH_WEST
= 320¶
-
TT
= 200¶
-
WEST
= 221¶
-
WEST_MID
= 312¶
-
above
(expand=None)[source]¶ Returns a new Region above the current region with a height of
expand
pixels.Does not include the current region. If range is omitted, it reaches to the top of the screen. The new region has the same width and x-position as the current region.
-
aboveAt
(offset=0)[source]¶ Returns point in the center of the region’s top side (offset to the top by negative
offset
)
-
below
(expand=None)[source]¶ Returns a new Region below the current region with a height of
expand
pixels.Does not include the current region. If range is omitted, it reaches to the bottom of the screen. The new region has the same width and x-position as the current region.
-
bottomAt
(offset=0)[source]¶ Returns point in the center of the region’s bottom side (offset to the bottom by
offset
)
-
click
(target=None, modifiers='')[source]¶ Moves the cursor to the target location and clicks the default mouse button.
-
clipRegionToScreen
()[source]¶ Returns the part of the region that is visible on a screen
If the region equals to all visible screens, returns Screen(-1). If the region is visible on multiple screens, returns the screen with the smallest ID. Returns None if the region is outside the screen.
-
debugPreview
(title='Debug')[source]¶ Displays the region in a preview window.
If the region is a Match, circles the target area. If the region is larger than half the primary screen in either dimension, scales it down to half size.
-
doubleClick
(target=None, modifiers='')[source]¶ Moves the cursor to the target location and double-clicks the default mouse button.
-
drag
(dragFrom=None)[source]¶ Starts a dragDrop operation.
Moves the cursor to the target location and clicks the mouse in preparation to drag a screen element
-
dragDrop
(target, target2=None, modifiers='')[source]¶ Performs a dragDrop operation.
Holds down the mouse button on
dragFrom
, moves the mouse todragTo
, and releases the mouse button.modifiers
may be a typeKeys() compatible string. The specified keys will be held during the drag-drop operation.
-
dropAt
(dragTo=None, delay=None)[source]¶ Completes a dragDrop operation
Moves the cursor to the target location, waits
delay
seconds, and releases the mouse button
-
exists
(pattern, seconds=None)[source]¶ Searches for an image pattern in the given region
Returns Match if pattern exists, None otherwise (does not throw exception) Sikuli supports OCR search with a text parameter. This does not (yet).
-
find
(pattern)[source]¶ Searches for an image pattern in the given region
Throws
FindFailed
exception if the image could not be found. Sikuli supports OCR search with a text parameter. This does not (yet).
-
findAll
(pattern)[source]¶ Searches for an image pattern in the given region
Returns
Match
object ifpattern
exists, empty array otherwise (does not throw exception). Sikuli supports OCR search with a text parameter. This does not (yet).
-
findAllByRow
(target)[source]¶ Returns an array of rows in the region (defined by the raster), each row containing all matches in that row for the target pattern.
-
findAllBycolumn
(target)[source]¶ Returns an array of columns in the region (defined by the raster), each column containing all matches in that column for the target pattern.
-
get
(part)[source]¶ Returns a section of the region as a new region
Accepts partitioning constants, e.g. Region.NORTH, Region.NORTH_WEST, etc. Also accepts an int 200-999: * First digit: Raster (n rows by n columns) * Second digit: Row index (if equal to raster, gets the whole row) * Third digit: Column index (if equal to raster, gets the whole column)
Region.get(522) will use a raster of 5 rows and 5 columns and return the cell in the middle.
Region.get(525) will use a raster of 5 rows and 5 columns and return the row in the middle.
-
getBitmap
()[source]¶ Captures screen area of this region, at least the part that is on the screen
Returns image as numpy array
-
getClipboard
()[source]¶ Returns the contents of the clipboard
Can be used to pull outside text into the application, if it is first copied with the OS keyboard shortcut (e.g., “Ctrl+C”)
-
getCol
(column, numberColumns=None)[source]¶ Returns the specified column of the region (if the raster is set)
If numberColumns is provided, uses that instead of the raster
-
getRow
(row, numberRows=None)[source]¶ Returns the specified row of the region (if the raster is set)
If numberRows is provided, uses that instead of the raster
-
getScreen
()[source]¶ Return an instance of the
Screen
object this region is inside.Checks the top left corner of this region (if it touches multiple screens) is inside. Returns None if the region isn’t positioned in any screen.
-
getThrowException
()[source]¶ Returns True if an exception will be thrown for FindFailed operations, False otherwise.
-
grow
(width, height=None)[source]¶ Expands the region by
width
on both sides andheight
on the top and bottom.If only one value is provided, expands the region by that amount on all sides. Equivalent to
nearby()
.
-
hasObserver
()[source]¶ Check whether at least one event is registered for this region.
The observer may or may not be running.
-
highlight
(*args)[source]¶ Highlights the region with a colored frame. Accepts the following parameters:
highlight([toEnable], [seconds], [color])
- toEnable (boolean): Enables or disables the overlay
- seconds (number): Seconds to show overlay
- color (string): Hex code (“#XXXXXX”) or color name (“black”)
-
intersection
()[source]¶ Returns a new region that contains the overlapping portion of this region and the specified region (may be None)
-
isChanged
(min_changed_pixels, screen_state)[source]¶ Returns true if at least
min_changed_pixels
are different betweenscreen_state
and the current state.
-
isRegionValid
()[source]¶ Returns false if the whole region is not even partially inside any screen, otherwise true
-
left
(expand=None)[source]¶ Returns a new Region left of the current region with a width of
expand
pixels.Does not include the current region. If range is omitted, it reaches to the left border of the screen. The new region has the same height and y-position as the current region.
-
leftAt
(offset=0)[source]¶ Returns point in the center of the region’s left side (offset to the left by negative
offset
)
-
moveTo
(location)¶ Change the upper left-hand corner to a new
Location
Doesn’t change width or height
-
nearby
(expand=50)[source]¶ Returns a new Region that includes the nearby neighbourhood of the the current region.
The new region is defined by extending the current region’s dimensions all directions by range number of pixels. The center of the new region remains the same.
-
observe
(seconds=None)[source]¶ Begins the observer loop (synchronously).
Loops for
seconds
or until this region’s stopObserver() method is called. Ifseconds
is None, the observer loop cycles until stopped. If this method is called while the observer loop is already running, it returns False.Returns True if the observer could be started, False otherwise.
-
observeInBackground
(seconds=None)[source]¶ As Region.observe(), but runs in a background process, allowing the rest of your script to continue.
Note that the subprocess operates on copies of the usual objects, not the original Region object itself for example. If your event handler needs to share data with your main process, check out the documentation for the
multiprocessing
module to set up shared memory.
-
offset
(location, dy=0)[source]¶ Returns a new
Region
offset from this one bylocation
Width and height remain the same
-
onAppear
(pattern, handler=None)[source]¶ Registers an event to call
handler
whenpattern
appears in this region.The
handler
function should take one parameter, an ObserveEvent object (see below). This event is ignored in the future unless the handler calls the repeat() method on the provided ObserveEvent object.Returns the event’s ID as a string.
-
onChange
(min_changed_pixels=None, handler=None)[source]¶ Registers an event to call
handler
when at leastmin_changed_pixels
change in this region.(Default for min_changed_pixels is set in Settings.ObserveMinChangedPixels)
The
handler
function should take one parameter, an ObserveEvent object (see below). This event is ignored in the future unless the handler calls the repeat() method on the provided ObserveEvent object.Returns the event’s ID as a string.
-
onVanish
(pattern, handler=None)[source]¶ Registers an event to call
handler
whenpattern
disappears from this region.The
handler
function should take one parameter, an ObserveEvent object (see below). This event is ignored in the future unless the handler calls the repeat() method on the provided ObserveEvent object.Returns the event’s ID as a string.
-
paste
(*args)[source]¶ Usage: paste([PSMRL], text)
If a pattern is specified, the pattern is clicked first. Doesn’t support text paths.
text
is pasted as is using the OS paste shortcut (Ctrl+V for Windows/Linux, Cmd+V for OS X). Note that paste() does NOT use special formatting like type().
-
right
(expand=None)[source]¶ Returns a new Region right of the current region with a width of
expand
pixels.Does not include the current region. If range is omitted, it reaches to the right border of the screen. The new region has the same height and y-position as the current region.
-
rightAt
(offset=0)[source]¶ Returns point in the center of the region’s right side (offset to the right by
offset
)
-
rightClick
(target=None, modifiers='')[source]¶ Moves the cursor to the target location and clicks the right mouse button.
-
saveLastScreenImage
()[source]¶ Saves the last image taken on this region’s screen to a temporary file
-
setCols
(columns)[source]¶ Sets the number of columns in the raster (if rows have not been initialized, set to 1 as well)
-
setFindFailedHandler
(handler)[source]¶ Set a handler to receive FindFailed events (instead of triggering an exception).
-
setFindFailedResponse
(response)[source]¶ Set the response to a FindFailed exception in this region.
Can be ABORT, SKIP, PROMPT, or RETRY.
-
setImageMissingHandler
(handler)[source]¶ Set a handler to receive ImageMissing events (instead of triggering an exception).
-
setInactive
(name)[source]¶ The specified event is ignored until reactivated or until the observer restarts.
-
setLocation
(location)[source]¶ Change the upper left-hand corner to a new
Location
Doesn’t change width or height
-
setObserveScanRate
(scan_rate)[source]¶ Set the number of times per second the observe loop should run
-
setRaster
(rows, columns)[source]¶ Sets the raster for the region, allowing sections to be indexed by row/column
-
setRect
(*args)[source]¶ Sets the rect of the region. Accepts the following arguments:
setRect(rect_tuple) setRect(x, y, w, h) setRect(rect_region)
-
setRows
(rows)[source]¶ Sets the number of rows in the raster (if columns have not been initialized, set to 1 as well)
-
setThrowException
(setting)[source]¶ Defines whether an exception should be thrown for FindFailed operations.
setting
should be True or False.
-
setWaitScanRate
(seconds=None)[source]¶ Set this Region’s scan rate
A find op should repeat the search for the given Visual rate times per second until found or the maximum waiting time is reached.
-
stopObserver
()[source]¶ Stops this region’s observer loop.
If this is running in a subprocess, the subprocess will end automatically.
-
type
(*args)[source]¶ Usage: type([PSMRL], text, [modifiers])
If a pattern is specified, the pattern is clicked first. Doesn’t support text paths.
Special keys can be entered with the key name between brackets, as “{SPACE}”, or as Key.SPACE.
-
wait
(pattern, seconds=None)[source]¶ Searches for an image pattern in the given region, given a specified timeout period
Functionally identical to find(). If a number is passed instead of a pattern, just waits the specified number of seconds. Sikuli supports OCR search with a text parameter. This does not (yet).
-
waitVanish
(pattern, seconds=None)[source]¶ Waits until the specified pattern is not visible on screen.
If
seconds
pass and the pattern is still visible, raises FindFailed exception. Sikuli supports OCR search with a text parameter. This does not (yet).
-
lackey.Pattern class¶
lackey.Match class¶
lackey.Screen class¶
-
class
lackey.
Screen
(screenId=None)[source]¶ Bases:
lackey.RegionMatching.Region
Individual screen objects can be created for each monitor in a multi-monitor system.
Screens are indexed according to the system order. 0 is the primary monitor (display 1), 1 is the next monitor, etc.
Lackey also makes it possible to search all screens as a single “virtual screen,” arranged according to the system’s settings. Screen(-1) returns this virtual screen. Note that the larger your search region is, the slower your search will be, so it’s best practice to adjust your region to the particular area of the screen where you know your target will be.
Note that Sikuli is inconsistent in identifying screens. In Windows, Sikuli identifies the first hardware monitor as Screen(0) rather than the actual primary monitor. However, on OS X it follows the latter convention. We’ve opted to make Screen(0) the actual primary monitor (wherever the Start Menu/System Menu Bar is) across the board.
-
captureForHighlight
(*args)¶ Captures the region as an image
-
getID
()¶ Returns screen ID
-
classmethod
getNumberScreens
()[source]¶ Get the number of screens in a multi-monitor environment at the time the script is running
-
newLocation
(loc)[source]¶ Creates a new location on this screen, with the same offset it would have had on the default screen
-
newRegion
(loc, width, height)[source]¶ Creates a new region on the current screen at the specified offset with the specified width and height.
-
primaryScreen
= 0¶
-
lackey.Location class¶
-
class
lackey.
Location
(x, y)[source]¶ Bases:
object
Basic 2D point object
-
copyTo
(screen)[source]¶ Creates a new point with the same offset on the target screen as this point has on the current screen
-
getMonitor
()[source]¶ Returns an instance of the
Screen
object this Location is inside.Returns the primary screen if the Location isn’t positioned in any screen.
-
getScreen
()[source]¶ Returns an instance of the
Screen
object this Location is inside.Returns None if the Location isn’t positioned in any screen.
-
grow
(*args)[source]¶ Creates a region around the given point Valid arguments:
grow(wh)
- Creates a region centered on this point with a width and height ofwh
.grow(w, h)
- Creates a region centered on this point with a width ofw
and height ofh
.grow(Region.CREATE_X_DIRECTION, Region.CREATE_Y_DIRECTION, w, h)
- Creates a region with this point as one corner, expanding in the specified direction
-
move
(x, y)¶ Set the location of this object to the specified coordinates.
-
moveTo
(x, y)¶ Set the location of this object to the specified coordinates.
-
lackey.Mouse class¶
-
class
lackey.
Mouse
[source]¶ Bases:
object
Mid-level mouse routines.
-
LEFT
¶
-
MIDDLE
¶
-
RIGHT
¶
-
WHEEL_DOWN
= 0¶
-
WHEEL_UP
= 1¶
-
at
()¶ Gets
Location
of cursor
Holds down the specified mouse button.
Use Mouse.LEFT, Mouse.MIDDLE, Mouse.RIGHT
Releases the specified mouse button.
Use Mouse.LEFT, Mouse.MIDDLE, Mouse.RIGHT
-
click
(loc=None, button=<Mock id='139888181612176'>)[source]¶ Clicks the specified mouse button.
If
loc
is set, move the mouse to that Location first.Use button constants Mouse.LEFT, Mouse.MIDDLE, Mouse.RIGHT
-
down
(button=<Mock id='139888181612304'>)¶ Holds down the specified mouse button.
Use Mouse.LEFT, Mouse.MIDDLE, Mouse.RIGHT
-
move
(loc, yoff=None)[source]¶ Moves cursor to specified location. Accepts the following arguments:
move(loc)
- Move cursor toLocation
move(xoff, yoff)
- Move cursor to offset from current location
-
moveSpeed
(location, seconds=0.3)[source]¶ Moves cursor to specified
Location
overseconds
.If
seconds
is 0, moves the cursor immediately. Used for smooth somewhat-human-like motion.
-
up
(button=<Mock id='139888181612496'>)¶ Releases the specified mouse button.
Use Mouse.LEFT, Mouse.MIDDLE, Mouse.RIGHT
-
lackey.Keyboard class¶
-
class
lackey.
Keyboard
[source]¶ Bases:
object
Mid-level keyboard routines. Interfaces with
PlatformManager
-
keyDown
(keys)[source]¶ Accepts a string of keys (including special keys wrapped in brackets or provided by the Key or KeyModifier classes). Holds down all of them.
-
lackey.App class¶
-
class
lackey.
App
(identifier=None)[source]¶ Bases:
object
Allows apps to be selected by title, PID, or by starting an application directly. Can address individual windows tied to an app.
For more information, see Sikuli’s App documentation.
-
classmethod
close
(appName)[source]¶ Closes the process associated with the specified app.
As a class method, accessible as App.class(appName). As an instance method, accessible as App(appName).close().
-
classmethod
focus
(appName)[source]¶ Searches for exact text, case insensitive, anywhere in the window title.
Brings the matching window to the foreground.
As a class method, accessible as App.focus(appName). As an instance method, accessible as App(appName).focus().
-
classmethod
focusedWindow
()[source]¶ Returns a Region corresponding to whatever window is in the foreground
-
getPID
()[source]¶ Returns the PID for the associated app (or -1, if no app is associated or the app is not running)
-
getWindow
()[source]¶ Returns the title of the main window of the currently open app.
Returns an empty string if no match could be found.
-
isRunning
(waitTime=0)[source]¶ If PID isn’t set yet, checks if there is a window with the specified title.
-
classmethod
lackey.Key class¶
-
class
lackey.
Key
[source]¶ Key codes for InputEmulation.Keyboard object.
Can be entered directly or concatenated with an existing string, e.g.
type(Key.TAB)
-
ADD
= '{ADD}'¶
-
ALT
= '{ALT}'¶
-
BACKSPACE
= '{BACKSPACE}'¶
-
CAPS_LOCK
= '{CAPS_LOCK}'¶
-
CMD
= '{CMD}'¶
-
CTRL
= '{CTRL}'¶
-
DELETE
= '{DELETE}'¶
-
DIVIDE
= '{DIVIDE}'¶
-
DOWN
= '{DOWN}'¶
-
END
= '{END}'¶
-
ENTER
= '{ENTER}'¶
-
ESC
= '{ESC}'¶
-
F1
= '{F1}'¶
-
F10
= '{F10}'¶
-
F11
= '{F11}'¶
-
F12
= '{F12}'¶
-
F13
= '{F13}'¶
-
F14
= '{F14}'¶
-
F15
= '{F15}'¶
-
F16
= '{F16}'¶
-
F2
= '{F2}'¶
-
F3
= '{F3}'¶
-
F4
= '{F4}'¶
-
F5
= '{F5}'¶
-
F6
= '{F6}'¶
-
F7
= '{F7}'¶
-
F8
= '{F8}'¶
-
F9
= '{F9}'¶
-
HOME
= '{HOME}'¶
-
INSERT
= '{INSERT}'¶
-
LEFT
= '{LEFT}'¶
-
META
= '{META}'¶
-
MINUS
= '{MINUS}'¶
-
MULTIPLY
= '{MULTIPLY}'¶
-
NUM0
= '{NUM0}'¶
-
NUM1
= '{NUM1}'¶
-
NUM2
= '{NUM2}'¶
-
NUM3
= '{NUM3}'¶
-
NUM4
= '{NUM4}'¶
-
NUM5
= '{NUM5}'¶
-
NUM6
= '{NUM6}'¶
-
NUM7
= '{NUM7}'¶
-
NUM8
= '{NUM8}'¶
-
NUM9
= '{NUM9}'¶
-
NUM_LOCK
= '{NUM_LOCK}'¶
-
PAGE_DOWN
= '{PAGE_DOWN}'¶
-
PAGE_UP
= '{PAGE_UP}'¶
-
PAUSE
= '{PAUSE}'¶
-
PRINTSCREEN
= '{PRINTSCREEN}'¶
-
RIGHT
= '{RIGHT}'¶
-
SCROLL_LOCK
= '{SCROLL_LOCK}'¶
-
SEPARATOR
= '{SEPARATOR}'¶
-
SHIFT
= '{SHIFT}'¶
-
SPACE
= '{SPACE}'¶
-
TAB
= '{TAB}'¶
-
UP
= '{UP}'¶
-
WIN
= '{WIN}'¶
-
lackey.KeyModifier class¶
lackey.PlatformManagerWindows class¶
-
lackey.
PlatformManagerWindows
¶ alias of
lackey.PlatformManagerWindows
lackey.Debug class¶
-
class
lackey.
DebugMaster
[source]¶ Bases:
object
Used to create the global Debug object
-
error
(message)[source]¶ Records an Error-level log message
Uses the log path defined by
Debug.setUserLogFile()
. If no log file is defined, sends to STDOUT
-
history
(message)[source]¶ Records an Action-level log message
Uses the log path defined by
Debug.setUserLogFile()
. If no log file is defined, sends to STDOUT
-
info
(message)[source]¶ Records an Info-level log message
Uses the log path defined by
Debug.setUserLogFile()
. If no log file is defined, sends to STDOUT
-
log
(level, message)[source]¶ Records a Debug-level log message Uses the log path defined by
Debug.setUserLogFile()
. If no log file is defined, sends to STDOUT
-
lackey.Settings class¶
-
class
lackey.
SettingsMaster
[source]¶ Bases:
object
Global settings that Lackey refers to by default
-
ActionLogs
= True¶
-
BundlePath
= '/home/docs/checkouts/readthedocs.org/user_builds/lackey/envs/latest/bin'¶
-
ClickDelay
= 0.0¶
-
DebugLogs
= False¶
-
DelayBeforeDrag
= 0.3¶
-
DelayBeforeDrop
= 0.3¶
-
DelayBeforeMouseDown
= 0.3¶
-
ErrorLogs
= False¶
-
ImagePaths
= []¶
-
InfoLogs
= True¶
-
LogTime
= False¶
-
MinSimilarity
= 0.7¶
-
MoveMouseDelay
= 0.3¶
-
OberveMinChangedPixels
= 50¶
-
ObserveScanRate
= 3¶
-
OcrDataPath
= None¶
-
PopupLocation
= None¶
-
ShowActions
= False¶
-
SlowMotionDelay
= 3¶
-
TypeDelay
= 0.0¶
-
UserLogPrefix
= 'user'¶
-
UserLogTime
= True¶
-
UserLogs
= True¶
-
WaitScanRate
= 3¶
-
lackey.FindFailed class¶
Sikuli Convenience Functions¶
-
lackey.
setShowActions
(value)[source]¶ Convenience function. Sets “show actions” setting (True or False)
-
lackey.
getBundleFolder
()[source]¶ Convenience function. Same as getBundlePath() plus the OS default path separator.
-
lackey.
addImagePath
(new_path)[source]¶ Convenience function. Adds a path to the list of paths to search for images.
Can be a URL (but must be accessible).
-
lackey.
getParentPath
()[source]¶ Convenience function. Returns the parent folder of the *.sikuli bundle.
-
lackey.
getParentFolder
()[source]¶ Convenience function. Same as getParentPath() plus the OS default path separator.
-
lackey.
makePath
(*args)[source]¶ Convenience function. Returns a path from a series of path components.
Same as os.path.join.
-
lackey.
makeFolder
(*args)[source]¶ Convenience function. Same as makePath() plus the OS default path separator.
-
lackey.
unzip
(from_file, to_folder)[source]¶ Convenience function.
Extracts files from the zip file fromFile into the folder toFolder.
-
lackey.
popError
(text, title='Lackey Error')[source]¶ Creates an error dialog with the specified text.
-
lackey.
popAsk
(text, title='Lackey Decision')[source]¶ Creates a yes-no dialog with the specified text.
-
lackey.
input
(msg='', default='', title='Lackey Input', hidden=False)[source]¶ Creates an input dialog with the specified message and default text.
If hidden, creates a password dialog instead. Returns the entered value.
-
lackey.
inputText
(message='', title='Lackey Input', lines=9, width=20, text='')[source]¶ Creates a textarea dialog with the specified message and default text.
Returns the entered value.