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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd image of UI element to be recognized in automation processes.voidAdd image of UI element to be recognized in automation processes.voidaltE()voidaltE(int waitAfter) voidaltF()voidaltF(int waitAfter) voidaltF4()voidaltF4(int waitAfter) voidaltPlusLetter(char c) voidaltPlusLetter(char c, int waitAfter) voidaltR()voidaltR(int waitAfter) voidaltSpace()voidaltSpace(int waitAfter) voidaltU()voidaltU(int waitAfter) voidvoidbackspace(int waitAfter) voidInvoke the default browser passing a URLvoidclick()Click in last found UI element.voidclick(int waitAfter) voidclickAt(int px, int py) voidclickAt(int px, int py, int numClicks) booleanbooleanclickOn(org.marvinproject.framework.image.MarvinImage visualElem) voidclickRelative(int x, int y) Click relative the last found UI element.voidcontrolA()voidcontrolA(int waitAfter) voidcontrolC()voidcontrolC(int waitAfter) voidvoidcontrolEnd(int waitAfter) voidcontrolF()voidcontrolF(int waitAfter) voidvoidcontrolHome(int waitAfter) voidcontrolP()voidcontrolP(int waitAfter) voidcontrolR()voidcontrolR(int waitAfter) voidvoidcontrolShiftJ(int waitAfter) voidvoidcontrolShiftP(int waitAfter) voidcontrolT()voidcontrolT(int waitAfter) voidcontrolU()voidcontrolU(int waitAfter) voidcontrolV()voidcontrolV(int waitAfter) voidcontrolW()voidcontrolW(int waitAfter) voidcopyToClipboard(String text) Copy content to the clipboardvoidcopyToClipboard(String text, int waitAfter) Copy content to the clipboardvoiddelete()voiddelete(int waitAfter) voidDouble-click in last found UI element.voiddoubleClickRelative(int x, int y) Double-click relative the last found UI element.voiddoubleClickRelative(int x, int y, int sleepBetweenClicks) Double-click relative the last found UI element.voidvoidenter()Press key "enter"voidenter(int waitAfter) Press key "enter"voidCommand line execution used to run commands or start applications.booleanfind(String elementId, int startX, int startY, int searchWidth, int searchHeight, Double elementMatching, int maxWaitingTime) booleanbooleanbooleanfind(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, int startX, int startY, int searchWidth, int searchHeight, Double elementMatching, int maxWaitingTime) booleanfind(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, Double elementMatching, int maxWaitingTime) booleanfind(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) booleanfindLastUntil(String elementId, int maxWaitingTime) booleanfindLastUntil(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, int maxWaitingTime) booleanfindLastUntil(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, Integer threshold, int maxWaitingTime) booleanfindRelative(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.MarvinSegmentfindSubimage(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.MarvinSegmentfindSubimage(org.marvinproject.framework.image.MarvinImage subimage, org.marvinproject.framework.image.MarvinImage imageIn, int startX, int startY, Double similarity, boolean findBest) booleanFind a text element in the UI.booleanFind a text element in the UI.booleanFind a text element in the UI.booleanFind a text element in the UI.booleanFind a text element in the UI.booleanFind a text element in the UI.booleanfindText(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, int maxWaitingTime) booleanfindText(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, int maxWaitingTime, boolean best) booleanfindText(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, Integer threshold, double matching, int maxWaitingTime) booleanfindText(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, Integer threshold, double matching, int maxWaitingTime, boolean best) booleanfindText(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, Integer threshold, int maxWaitingTime) booleanfindText(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, Integer threshold, int maxWaitingTime, boolean best) booleanfindText(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, Integer startX, Integer startY, Integer searchWidth, Integer searchHeight, Integer threshold, int maxWaitingTime, boolean best) booleanbooleanfindUntil(String elementId, Integer threshold, Double elementMatching, int maxWaitingTime, boolean best) booleanfindUntil(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, int startX, int startY, int searchWidth, int searchHeight, Integer threshold, Double elementMatching, int maxWaitingTime) booleanfindUntil(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, int startX, int startY, Integer threshold, Double elementMatching, int maxWaitingTime) booleanfindUntil(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, Integer threshold, Double elementMatching, int maxWaitingTime) booleanfindUntil(String elementId, org.marvinproject.framework.image.MarvinImage visualElem, Integer threshold, Double elementMatching, int maxWaitingTime, boolean best) booleanfindUntil(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.doublegetCoordinates(String elementImage, int maxWaitingTime, boolean best) Returns the last recognized UI element.getLastX()getLastY()getRobot()org.marvinproject.framework.image.MarvinImageReturns the current screen in MarvinImage format.voidHold key "shift"voidholdShift(int waitAfter) Hold key "shift"voidkeyDown()Press key "down"voidkeyDown(int waitAfter) Press key "down"voidkeyEnd()voidkeyEnd(int waitAfter) voidkeyEnter(int waitAfter) Press key "enter"voidkeyEsc()voidkeyEsc(int waitAfter) voidkeyF1()voidkeyF1(int waitAfter) voidkeyF10()voidkeyF10(int waitAfter) voidkeyF11()voidkeyF11(int waitAfter) voidkeyF12()voidkeyF12(int waitAfter) voidkeyF2()voidkeyF2(int waitAfter) voidkeyF3()voidkeyF3(int waitAfter) voidkeyF4()voidkeyF4(int waitAfter) voidkeyF5()voidkeyF5(int waitAfter) voidkeyF6()voidkeyF6(int waitAfter) voidkeyF7()voidkeyF7(int waitAfter) voidkeyF8()voidkeyF8(int waitAfter) voidkeyF9()voidkeyF9(int waitAfter) voidkeyLeft()Press key "left"voidkeyLeft(int waitAfter) Press key "left"voidkeyRight()Press key "right"voidkeyRight(int waitAfter) Press key "right"voidkeyUp()Press key "up"voidkeyUp(int waitAfter) Press key "up"voidvoidkeyWindows(int waitAfter) voidShortcut to maximize window on Windows Operating Systemvoidmove()Move cursor to the last found element.voidmoveRandom(int rangeX, int rangeY) voidmoveRelative(int x, int y) Move cursor relative the last found UI element.voidmoveTo(int x, int y) Move cursor to an specific coordinate.voidPaste content from the clipboard.voidPaste content from the clipboard.voidvoidRelease key "shift".voidRight Click in last found UI element.voidrightClickAt(int x, int y) voidrightClickRelative(int x, int y) voidsaveScreenshot(String path) Saves a screenshot in a given pathorg.marvinproject.framework.image.MarvinImagescreenCut(int x, int y, int width, int height) Returns a given region of the current screen in MarvinImage formatvoidscrollDown(int y) Scroll down wheel action.voidscrollUp(int y) Scroll up wheel action.voidsetColorSensibility(double colorSensibility) voidSet current UI element.voidsetResourceClassLoader(ClassLoader classloader) Set classloader for loading resources exported in JAR files.voidshiftTab()voidshiftTab(int waitAfter) voidspace()voidspace(int waitAfter) voidKey "Window" + R shortcut to run commands on windws UI.voidtab()Press key tabvoidtab(int waitAfter) Press key "tab"voidTriple-click in last found UI element.voidtripleClickRelative(int x, int y) Triple-click relative the last found UI element.voidType a text, char by char (inividual key events)voidType text, char by char.voidType text, char by char, specifying key interval timevoidPress a sequence of keys.voidtypeKeysWithInterval(Integer interval, Integer... keys) voidtypeWaitAfterChars(String text, int waitAfterChars) Type text, char by char, specifying key interval timevoidtypeWaitAfterChars(String text, int waitAfterChars, int waitAfter) Type text, char by char, specifying key interval timevoidwait(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
-