MSS API

Classes

GNU/Linux

class mss.linux.MSS
__init__(display=None)
Param:str display: display to use.

GNU/Linux initializations.

grab(monitor) → ScreenShot
Raises:ScreenShotError – When color depth is not 32 (rare).
Return type:ScreenShot

See mss.base.MSSBase.grab for details.

Methods

class mss.base.MSSBase

The parent’s class for every OS implementation.

grab(monitor) → ScreenShot
Parameters:monitor (dict) – monitor’s informations.
Raises:NotImplementedError – Subclasses need to implement this.
Return type:ScreenShot

Retrieve screen pixels for a given monitor.

Note

monitor can be a tuple like PIL.Image.grab() accepts, it will be converted to the approriate dict.

save(mon=1, output='screenshot.png', callback=None) → generator
Parameters:
  • mon (int) – the monitor’s number.
  • output (str) – the output’s file name. %d, if present, will be replaced by the monitor number.
  • callback (callable) – callback called before saving the screenshot to a file. Takes the output argument as parameter.
Return generator:
 

Created file(s).

Grab a screenshot and save it to a file.

shot() → str
Return str:The created file.

Helper to save the screenshot of the first monitor, by default. You can pass the same arguments as for save.

New in version 3.0.0.

class mss.base.ScreenShot

Screen shot object.

Note

A better name would have been Image, but to prevent collisions with PIL.Image, it has been decided to use ScreenShot.

classmethod from_size(cls, data, width, height) → ScreenShot
Parameters:
  • data (bytearray) – raw BGRA pixels retrieved by ctype OS independent implementations.
  • width (int) – the monitor’s width.
  • height (int) – the monitor’s height.
Return type:

ScreenShot

Instanciate a new class given only screenshot’s data and size.

pixels(coord_x, coord_y) → Tuple[int, int, int]
Parameters:
  • coord_x (int) – The x coordinate.
  • coord_y (int) – The y coordinate.
Return type:

Tuple[int, int, int]

Get the pixel value at the given position.

New in version 3.0.0.

Properties

class mss.base.MSSBase
monitors

Positions of all monitors. If the monitor has rotation, you have to deal with it inside this method.

This method has to fill self._monitors with all informations and use it as a cache:

  • self._monitors[0] is a dict of all monitors together
  • self._monitors[N] is a dict of the monitor N (with N > 0)

Each monitor is a dict with:

  • left: the x-coordinate of the upper-left corner
  • top: the y-coordinate of the upper-left corner
  • width: the width
  • height: the height
Type:List[Dict[str, int]]
class mss.base.ScreenShot
__array_interface__

Numpy array interface support. It uses raw data in BGRA form.

Type:Dict[str, Any]
pos

The screen shot’s coodinates.

Type:NamedTuple
top

The screen shot’s top coodinate.

Type:int
left

The screen shot’s left coodinate. :type: int

size

The screen shot’s size.

Type:NamedTuple
width

The screen shot’s width.

Type:int
height

The screen shot’s height.

Type:int
pixels

List of RGB tuples.

Type:List[Tuple[int, int, int]]
rgb

Computed RGB values from the BGRA raw pixels.

Type:bytes

New in version 3.0.0.

Exception

exception mss.exception.ScreenShotError

Base class for MSS exceptions.

Factory

mss.factory.mss() → MSSBase

Factory function to instance the appropriate MSS class.