Skip to content

Display

Using the methods below you will be able to interact with the display.

Getting display size

Using the display size method, you can get the screen dimension (width and height) in pixels.

# Defining a variable to receive the display_size method.
display_size = bot.display_size()

# Print the display size in pixels.
print(display_size)
// Method not implemented.
// Defining a variable to receive the display_size method.
const display_size = await desktopBot.display_size()

// Print the display size in pixels.
console.log(display_size)
// Defining a variable to receive the display_size method.
const display_size: displaySize = await desktopBot.display_size()

// Print the display size in pixels.
console.log(display_size)

Getting screenshot

With the get screenshot method, it is possible to take a screenshot and save it in any directory passing the path as a parameter.

# Take a screenshot, save the file path given and return the screenshot Image object.
bot.get_screenshot(filepath='my_screenshot_with_method_get_screenshot.png')

Tip

The method takes an optional parameter region which is a tuple with values ​​of left, top, width and height to cut part of the screen. Learn more at the full API documentation.

// Take a screenshot and return the screenshot MarvinImage object.
MarvinImage screen = getScreenShot();
// Take a screenshot, save it if the file path is given and return the file path.
await desktopBot.screenshot('/home/user/', 'my_screenshot_with_method_get_screenshot.png')
// Take a screenshot, save it if the file path is given and return the file path.
await desktopBot.screenshot('/home/user/', 'my_screenshot_with_method_get_screenshot.png')

Getting partial screenshot

As we saw above, it is possible to take a screenshot of the entire screen. Using the screen cut method and passing as parameters the x and y coordinates along with the width and height, only the indicated area will be collected.

# Capturing part of the screen.
screen_cut = bot.screen_cut(x=702, y=380, width=120, height=80)

# The variable `screen_cut` is the screenshot Image object returned.
// Capturing part of the screen.
MarvinImage screen = screenCut(702, 380, 120, 80);

// The variable `screen` is the screenshot MarvinImage object returned.
// Capturing part of the screen.
const screen = await desktopBot.screenCut(702, 380, 120, 80);
// Capturing part of the screen.
const screen: Image = await desktopBot.screenCut(702, 380, 120, 80);

Saving a screenshot

The save screenshot has pretty much the same functionality as the get_screenshot and screenshot methods.

The only difference is that it does not return an Image object but instead, it simply saves the image on disk.

# Take and save a screenshot.
bot.save_screenshot("screenshot.png")
// Take and save a screenshot.
saveScreenshot("screenshot.png");
// Take a screenshot, save it if the file path is given and return the file path.
await desktopBot.screenshot('/home/user/', 'my_screenshot_with_method_get_screenshot.png')
// Take a screenshot, save it if the file path is given and return the file path.
await desktopBot.screenshot('/home/user/', 'my_screenshot_with_method_get_screenshot.png')