Package dev.botcity.framework.bot
Class DesktopBot
java.lang.Object
dev.botcity.framework.bot.DesktopBot
Provides a robot interface to operate desktop applications.
- Author:
- Gabriel Ambrósio Archanjo
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Add image of UI element to be recognized in automation processes.void
Add image of UI element to be recognized in automation processes.void
altE()
void
altE
(int waitAfter) void
altF()
void
altF
(int waitAfter) void
altF4()
void
altF4
(int waitAfter) void
altPlusLetter
(char c) void
altPlusLetter
(char c, int waitAfter) void
altR()
void
altR
(int waitAfter) void
altSpace()
void
altSpace
(int waitAfter) void
altU()
void
altU
(int waitAfter) void
void
backspace
(int waitAfter) void
Invoke the default browser passing a URLvoid
click()
Click in last found UI element.void
click
(int waitAfter) void
clickAt
(int px, int py) void
clickAt
(int px, int py, int numClicks) boolean
boolean
clickOn
(org.marvinproject.framework.image.MarvinImage visualElem) void
clickRelative
(int x, int y) Click relative the last found UI element.void
controlA()
void
controlA
(int waitAfter) void
controlC()
void
controlC
(int waitAfter) void
void
controlEnd
(int waitAfter) void
controlF()
void
controlF
(int waitAfter) void
void
controlHome
(int waitAfter) void
controlP()
void
controlP
(int waitAfter) void
controlR()
void
controlR
(int waitAfter) void
void
controlShiftJ
(int waitAfter) void
void
controlShiftP
(int waitAfter) void
controlT()
void
controlT
(int waitAfter) void
controlU()
void
controlU
(int waitAfter) void
controlV()
void
controlV
(int waitAfter) void
controlW()
void
controlW
(int waitAfter) void
copyToClipboard
(String text) Copy content to the clipboardvoid
copyToClipboard
(String text, int waitAfter) Copy content to the clipboardvoid
delete()
void
delete
(int waitAfter) void
Double-click in last found UI element.void
doubleClickRelative
(int x, int y) Double-click relative the last found UI element.void
doubleClickRelative
(int x, int y, int sleepBetweenClicks) Double-click relative the last found UI element.void
void
enter()
Press key "enter"void
enter
(int waitAfter) Press key "enter"void
Command line execution used to run commands or start applications.boolean
find
(String elementId, int startX, int startY, int searchWidth, int searchHeight, Double elementMatching, int maxWaitingTime) boolean
boolean
boolean
find
(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, int startX, int startY, int searchWidth, int searchHeight, Double elementMatching, int maxWaitingTime) boolean
find
(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, Double elementMatching, int maxWaitingTime) boolean
find
(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, Double elementMatching, int maxWaitingTime, boolean best) findAllSubimages
(org.marvinproject.framework.image.MarvinImage subimage, org.marvinproject.framework.image.MarvinImage imageIn, int startX, int startY, int searchWindowWidth, int searchWindowHeight, Double similarity) findAllUntil
(String elementId, double elementMatching, int maxWaitingTime) findAllUntil
(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, Integer startX, Integer startY, Integer searchWindowWidth, Integer searchWindowHeight, Integer threshold, Double elementMatching, int maxWaitingTime) boolean
findLastUntil
(String elementId, int maxWaitingTime) boolean
findLastUntil
(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, int maxWaitingTime) boolean
findLastUntil
(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, Integer threshold, int maxWaitingTime) boolean
findRelative
(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, UIElement anchor, int xDiff, int yDiff, int searchWindowWidth, int searchWindowHeight, Integer threshold, Double elementMatching, int maxWaitingTim, boolean best) org.marvinproject.framework.image.MarvinSegment
findSubimage
(org.marvinproject.framework.image.MarvinImage subimage, org.marvinproject.framework.image.MarvinImage imageIn, int startX, int startY, int searchWindowWidth, int searchWindowHeight, Double similarity, boolean findBest) org.marvinproject.framework.image.MarvinSegment
findSubimage
(org.marvinproject.framework.image.MarvinImage subimage, org.marvinproject.framework.image.MarvinImage imageIn, int startX, int startY, Double similarity, boolean findBest) boolean
Find a text element in the UI.boolean
Find a text element in the UI.boolean
Find a text element in the UI.boolean
Find a text element in the UI.boolean
Find a text element in the UI.boolean
Find a text element in the UI.boolean
findText
(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, int maxWaitingTime) boolean
findText
(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, int maxWaitingTime, boolean best) boolean
findText
(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, Integer threshold, double matching, int maxWaitingTime) boolean
findText
(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, Integer threshold, double matching, int maxWaitingTime, boolean best) boolean
findText
(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, Integer threshold, int maxWaitingTime) boolean
findText
(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, Integer threshold, int maxWaitingTime, boolean best) boolean
findText
(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, Integer startX, Integer startY, Integer searchWidth, Integer searchHeight, Integer threshold, int maxWaitingTime, boolean best) boolean
boolean
findUntil
(String elementId, Integer threshold, Double elementMatching, int maxWaitingTime, boolean best) boolean
findUntil
(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, int startX, int startY, int searchWidth, int searchHeight, Integer threshold, Double elementMatching, int maxWaitingTime) boolean
findUntil
(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, int startX, int startY, Integer threshold, Double elementMatching, int maxWaitingTime) boolean
findUntil
(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, Integer threshold, Double elementMatching, int maxWaitingTime) boolean
findUntil
(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, Integer threshold, Double elementMatching, int maxWaitingTime, boolean best) boolean
findUntil
(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, Integer startX, Integer startY, Integer searchWindowWidth, Integer searchWindowHeight, Integer threshold, Double elementMatching, int maxWaitingTime, boolean best) Get the current content in the clipboard.double
getCoordinates
(String elementImage, int maxWaitingTime, boolean best) Returns the last recognized UI element.getLastX()
getLastY()
getRobot()
org.marvinproject.framework.image.MarvinImage
Returns the current screen in MarvinImage format.void
Hold key "shift"void
holdShift
(int waitAfter) Hold key "shift"void
keyDown()
Press key "down"void
keyDown
(int waitAfter) Press key "down"void
keyEnd()
void
keyEnd
(int waitAfter) void
keyEnter
(int waitAfter) Press key "enter"void
keyEsc()
void
keyEsc
(int waitAfter) void
keyF1()
void
keyF1
(int waitAfter) void
keyF10()
void
keyF10
(int waitAfter) void
keyF11()
void
keyF11
(int waitAfter) void
keyF12()
void
keyF12
(int waitAfter) void
keyF2()
void
keyF2
(int waitAfter) void
keyF3()
void
keyF3
(int waitAfter) void
keyF4()
void
keyF4
(int waitAfter) void
keyF5()
void
keyF5
(int waitAfter) void
keyF6()
void
keyF6
(int waitAfter) void
keyF7()
void
keyF7
(int waitAfter) void
keyF8()
void
keyF8
(int waitAfter) void
keyF9()
void
keyF9
(int waitAfter) void
keyLeft()
Press key "left"void
keyLeft
(int waitAfter) Press key "left"void
keyRight()
Press key "right"void
keyRight
(int waitAfter) Press key "right"void
keyUp()
Press key "up"void
keyUp
(int waitAfter) Press key "up"void
void
keyWindows
(int waitAfter) void
Shortcut to maximize window on Windows Operating Systemvoid
move()
Move cursor to the last found element.void
moveRandom
(int rangeX, int rangeY) void
moveRelative
(int x, int y) Move cursor relative the last found UI element.void
moveTo
(int x, int y) Move cursor to an specific coordinate.void
Paste content from the clipboard.void
Paste content from the clipboard.void
void
Release key "shift".void
Right Click in last found UI element.void
rightClickAt
(int x, int y) void
rightClickRelative
(int x, int y) void
saveScreenshot
(String path) Saves a screenshot in a given pathorg.marvinproject.framework.image.MarvinImage
screenCut
(int x, int y, int width, int height) Returns a given region of the current screen in MarvinImage formatvoid
scrollDown
(int y) Scroll down wheel action.void
scrollUp
(int y) Scroll up wheel action.void
setColorSensibility
(double colorSensibility) void
Set current UI element.void
setResourceClassLoader
(ClassLoader classloader) Set classloader for loading resources exported in JAR files.void
shiftTab()
void
shiftTab
(int waitAfter) void
space()
void
space
(int waitAfter) void
Key "Window" + R shortcut to run commands on windws UI.void
tab()
Press key tabvoid
tab
(int waitAfter) Press key "tab"void
Triple-click in last found UI element.void
tripleClickRelative
(int x, int y) Triple-click relative the last found UI element.void
Type a text, char by char (inividual key events)void
Type text, char by char.void
Type text, char by char, specifying key interval timevoid
Press a sequence of keys.void
typeKeysWithInterval
(Integer interval, Integer... keys) void
typeWaitAfterChars
(String text, int waitAfterChars) Type text, char by char, specifying key interval timevoid
typeWaitAfterChars
(String text, int waitAfterChars, int waitAfter) Type text, char by char, specifying key interval timevoid
wait
(int ms) Wait / Sleep for a given interval.
-
Constructor Details
-
DesktopBot
public DesktopBot()
-
-
Method Details
-
enableDebug
public void enableDebug() -
setColorSensibility
public void setColorSensibility(double colorSensibility) -
getColorSensibility
public double getColorSensibility() -
setResourceClassLoader
Set classloader for loading resources exported in JAR files.- Parameters:
classloader
- Classloader to be used.
-
addImage
Add image of UI element to be recognized in automation processes. Check method find() and findText() to recognize such elements.- Parameters:
label
- The image identifier.path
- The path for the image on disk.- Throws:
IOException
- if not find the image.
-
addImage
Add image of UI element to be recognized in automation processes. Check method find() and findText() to recognize such elements.- Parameters:
label
- The image identifier.image
- The image to be added.
-
getRobot
-
getLastElement
Returns the last recognized UI element. In other words, the last element found by find() and findText()- Returns:
- The last recognized UI element.
-
exec
Command line execution used to run commands or start applications.- Parameters:
command
- The command to be executed.- Throws:
IOException
- If an I/O error occurs.
-
browse
Invoke the default browser passing a URL- Parameters:
uri
- The URL to be opened.- Throws:
IOException
- If an I/O error occurs.
-
clickOn
-
clickOn
public boolean clickOn(org.marvinproject.framework.image.MarvinImage visualElem) -
getLastX
-
getLastY
-
findText
Find a text element in the UI. Text elements are processed in black and white. Therefore, avoid using this method for texts in colored backgrounds.- Parameters:
elementId
- element to be foundmaxWaitingTime
- maximum time for searching the element on the UIbest
- return the best element? Search in the entire UI. If false, returns the first element that matches the criteria.- Returns:
- true if the UI element was found, false otherwise
-
findText
Find a text element in the UI. Text elements are processed in black and white. Therefore, avoid using this method for texts in colored backgrounds.- Parameters:
elementId
- element to be foundmaxWaitingTime
- maximum time for searching the element on the UI- Returns:
- true if the UI element was found, false otherwise
-
findText
public boolean findText(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, int maxWaitingTime, boolean best) -
findText
public boolean findText(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, int maxWaitingTime) -
findText
Find a text element in the UI. Text elements are processed in black and white. Therefore, avoid using this method for texts in colored backgrounds.- Parameters:
elementId
- element to be foundthreshold
- grayscale threshold for black and white processingmaxWaitingTime
- maximum time for searching the element on the UIbest
- Search in the entire UI for the best match or returns the first element that matches the criteria.- Returns:
- true if the UI element was found, false otherwise
-
findText
Find a text element in the UI. Text elements are processed in black and white. Therefore, avoid using this method for texts in colored backgrounds.- Parameters:
elementId
- element to be foundthreshold
- grayscale threshold for black and white processingmaxWaitingTime
- maximum time for searching the element on the UI- Returns:
- true if the UI element was found, false otherwise
-
findText
public boolean findText(String elementId, Integer threshold, double matching, int maxWaitingTime, boolean best) Find a text element in the UI. Text elements are processed in black and white. Therefore, avoid using this method for texts in colored backgrounds.- Parameters:
elementId
- element to be foundthreshold
- grayscale threshold for black and white processingmatching
- minimum score (0.0 to 1.0) to consider a match in the element image recognition process.maxWaitingTime
- maximum time for searching the element on the UIbest
- Search in the entire UI for the best match or returns the first element that matches the criteria.- Returns:
- true if the UI element was found, false otherwise
-
findText
Find a text element in the UI. Text elements are processed in black and white. Therefore, avoid using this method for texts in colored backgrounds.- Parameters:
elementId
- element to be foundthreshold
- grayscale threshold for black and white processingmatching
- minimum score (0.0 to 1.0) to consider a match in the element image recognition process.maxWaitingTime
- maximum time for searching the element on the UI- Returns:
- true if the UI element was found, false otherwise
-
findText
-
findText
-
findText
-
findText
-
findText
-
find
-
find
-
find
-
find
-
find
-
find
-
findUntil
-
findUntil
-
findUntil
-
findUntil
-
findUntil
-
findUntil
-
findRelative
-
findUntil
-
getCoordinates
-
findLastUntil
-
findLastUntil
public boolean findLastUntil(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, int maxWaitingTime) -
findLastUntil
-
clickAt
public void clickAt(int px, int py) -
clickAt
public void clickAt(int px, int py, int numClicks) -
rightClickAt
public void rightClickAt(int x, int y) -
click
public void click()Click in last found UI element. -
click
public void click(int waitAfter) -
setCurrentElement
Set current UI element.- Parameters:
el
- The current element.
-
rightClick
public void rightClick()Right Click in last found UI element. -
doubleclick
public void doubleclick()Double-click in last found UI element. -
clickRelative
public void clickRelative(int x, int y) Click relative the last found UI element.- Parameters:
x
- horizontal offset to the UI element.y
- vertical offset to the UI element.
-
rightClickRelative
public void rightClickRelative(int x, int y) -
doubleClickRelative
public void doubleClickRelative(int x, int y) Double-click relative the last found UI element.- Parameters:
x
- horizontal offset to the UI element.y
- vertical offset to the UI element.
-
doubleClickRelative
public void doubleClickRelative(int x, int y, int sleepBetweenClicks) Double-click relative the last found UI element.- Parameters:
x
- horizontal offset to the UI element.y
- vertical offset to the UI element.sleepBetweenClicks
- time in ms between individual click events.
-
tripleClick
public void tripleClick()Triple-click in last found UI element. -
tripleClickRelative
public void tripleClickRelative(int x, int y) Triple-click relative the last found UI element.- Parameters:
x
- horizontal offset to the UI element.y
- vertical offset to the UI element.
-
scrollDown
public void scrollDown(int y) Scroll down wheel action.- Parameters:
y
- wheel actions.
-
scrollUp
public void scrollUp(int y) Scroll up wheel action.- Parameters:
y
- wheel actions.
-
move
public void move()Move cursor to the last found element. -
moveTo
public void moveTo(int x, int y) Move cursor to an specific coordinate.- Parameters:
x
- coordinate xy
- coordinate y
-
moveRelative
public void moveRelative(int x, int y) Move cursor relative the last found UI element.- Parameters:
x
- horizontal offset to the UI Element.y
- vertical offset to the UI Element.
-
moveRandom
public void moveRandom(int rangeX, int rangeY) -
type
Type a text, char by char (inividual key events)- Parameters:
text
- text to be typed.
-
typeWaitAfterChars
Type text, char by char, specifying key interval time- Parameters:
text
- text to be typed.waitAfterChars
- time interval between key events.
-
typeWaitAfterChars
Type text, char by char, specifying key interval time- Parameters:
text
- text to be typed.waitAfterChars
- time interval between key events.waitAfter
- sleep interval after event.
-
type
Type text, char by char, specifying key interval time- Parameters:
text
- text to be typed.waitAfterChars
- time interval between key events.waitAfter
- sleep interval after event.
-
type
Type text, char by char.- Parameters:
text
- text to be typed.waitAfter
- sleep interval after action.
-
paste
Paste content from the clipboard.- Parameters:
text
- content to be pasted.
-
paste
Paste content from the clipboard.- Parameters:
text
- content to be pasted.waitAfter
- sleep interval after action.
-
copyToClipboard
Copy content to the clipboard- Parameters:
text
- content to copy.waitAfter
- sleep interval after action.
-
copyToClipboard
Copy content to the clipboard- Parameters:
text
- content to copy.
-
tab
public void tab()Press key tab -
tab
public void tab(int waitAfter) Press key "tab"- Parameters:
waitAfter
- sleep interval after action.
-
keyUp
public void keyUp(int waitAfter) Press key "up"- Parameters:
waitAfter
- sleep interval after action.
-
keyUp
public void keyUp()Press key "up" -
keyDown
public void keyDown(int waitAfter) Press key "down"- Parameters:
waitAfter
- sleep interval after action.
-
keyDown
public void keyDown()Press key "down" -
keyLeft
public void keyLeft()Press key "left" -
keyLeft
public void keyLeft(int waitAfter) Press key "left"- Parameters:
waitAfter
- sleep interval after action.
-
keyRight
public void keyRight()Press key "right" -
keyRight
public void keyRight(int waitAfter) Press key "right"- Parameters:
waitAfter
- sleep interval after action.
-
enter
public void enter()Press key "enter" -
enter
public void enter(int waitAfter) Press key "enter"- Parameters:
waitAfter
- sleep interval after action.
-
keyEnter
public void keyEnter(int waitAfter) Press key "enter"- Parameters:
waitAfter
- sleep interval after action.
-
keyEnd
public void keyEnd() -
keyEnd
public void keyEnd(int waitAfter) -
keyEsc
public void keyEsc() -
keyEsc
public void keyEsc(int waitAfter) -
keyF1
public void keyF1() -
keyF2
public void keyF2() -
keyF3
public void keyF3() -
keyF4
public void keyF4() -
keyF5
public void keyF5() -
keyF6
public void keyF6() -
keyF7
public void keyF7() -
keyF8
public void keyF8() -
keyF9
public void keyF9() -
keyF10
public void keyF10() -
keyF11
public void keyF11() -
keyF12
public void keyF12() -
keyF1
public void keyF1(int waitAfter) -
keyF2
public void keyF2(int waitAfter) -
keyF3
public void keyF3(int waitAfter) -
keyF4
public void keyF4(int waitAfter) -
keyF5
public void keyF5(int waitAfter) -
keyF6
public void keyF6(int waitAfter) -
keyF7
public void keyF7(int waitAfter) -
keyF8
public void keyF8(int waitAfter) -
keyF9
public void keyF9(int waitAfter) -
keyF10
public void keyF10(int waitAfter) -
keyF11
public void keyF11(int waitAfter) -
keyF12
public void keyF12(int waitAfter) -
holdShift
public void holdShift()Hold key "shift" -
holdShift
public void holdShift(int waitAfter) Hold key "shift"- Parameters:
waitAfter
- sleep interval after action.
-
releaseShift
public void releaseShift()Release key "shift". Need to be invoked after holdShift() method or similar. -
maximizeWindow
public void maximizeWindow()Shortcut to maximize window on Windows Operating System -
typeKeys
Press a sequence of keys. Hold the keys in the specified order, then release them.- Parameters:
keys
- array of key identification values like KeyEvent.VK_ENTERinterval
- interval between key presses.
-
typeKeysWithInterval
-
altPlusLetter
public void altPlusLetter(char c) -
altPlusLetter
public void altPlusLetter(char c, int waitAfter) -
altE
public void altE() -
altE
public void altE(int waitAfter) -
altR
public void altR() -
altR
public void altR(int waitAfter) -
altF
public void altF() -
altF
public void altF(int waitAfter) -
altU
public void altU() -
altU
public void altU(int waitAfter) -
altSpace
public void altSpace() -
altSpace
public void altSpace(int waitAfter) -
altF4
public void altF4() -
altF4
public void altF4(int waitAfter) -
controlC
public void controlC() -
controlC
public void controlC(int waitAfter) -
controlV
public void controlV() -
controlV
public void controlV(int waitAfter) -
controlA
public void controlA() -
controlA
public void controlA(int waitAfter) -
controlF
public void controlF() -
controlF
public void controlF(int waitAfter) -
controlP
public void controlP() -
controlP
public void controlP(int waitAfter) -
controlU
public void controlU() -
controlU
public void controlU(int waitAfter) -
controlR
public void controlR() -
controlR
public void controlR(int waitAfter) -
controlT
public void controlT() -
controlT
public void controlT(int waitAfter) -
controlEnd
public void controlEnd() -
controlEnd
public void controlEnd(int waitAfter) -
controlHome
public void controlHome(int waitAfter) -
controlHome
public void controlHome() -
controlW
public void controlW() -
controlW
public void controlW(int waitAfter) -
controlShiftP
public void controlShiftP() -
controlShiftP
public void controlShiftP(int waitAfter) -
controlShiftJ
public void controlShiftJ() -
controlShiftJ
public void controlShiftJ(int waitAfter) -
shiftTab
public void shiftTab() -
shiftTab
public void shiftTab(int waitAfter) -
getClipboard
Get the current content in the clipboard.- Returns:
- content in the clipboard.
-
keyWindows
public void keyWindows() -
keyWindows
public void keyWindows(int waitAfter) -
space
public void space() -
space
public void space(int waitAfter) -
backspace
public void backspace() -
backspace
public void backspace(int waitAfter) -
delete
public void delete() -
delete
public void delete(int waitAfter) -
getScreenShot
public org.marvinproject.framework.image.MarvinImage getScreenShot()Returns the current screen in MarvinImage format.- Returns:
- Image of the current screen in MarvinImage format.
-
screenCut
public org.marvinproject.framework.image.MarvinImage screenCut(int x, int y, int width, int height) Returns a given region of the current screen in MarvinImage format- Parameters:
x
- region start position x.y
- region start position y.width
- region's with.height
- region's height.- Returns:
- Image of the current screen in MarvinImage format.
-
saveScreenshot
Saves a screenshot in a given path- Parameters:
path
- desired path to save the screenshot.
-
startRun
Key "Window" + R shortcut to run commands on windws UI.- Parameters:
command
- command to execute.
-
print
-
wait
public void wait(int ms) Wait / Sleep for a given interval.- Parameters:
ms
- interval in milliseconds.
-
findSubimage
public org.marvinproject.framework.image.MarvinSegment findSubimage(org.marvinproject.framework.image.MarvinImage subimage, org.marvinproject.framework.image.MarvinImage imageIn, int startX, int startY, Double similarity, boolean findBest) -
findSubimage
public org.marvinproject.framework.image.MarvinSegment findSubimage(org.marvinproject.framework.image.MarvinImage subimage, org.marvinproject.framework.image.MarvinImage imageIn, int startX, int startY, int searchWindowWidth, int searchWindowHeight, Double similarity, boolean findBest) -
findAllUntil
-
findAllUntil
-
findAllSubimages
-