|
2 | 2 | Usage |
3 | 3 | ===== |
4 | 4 |
|
5 | | -Instance the good class |
6 | | ------------------------ |
| 5 | +Import |
| 6 | +====== |
7 | 7 |
|
8 | 8 | So MSS can be used as simply as:: |
9 | 9 |
|
10 | 10 | from mss import mss |
11 | 11 |
|
12 | | - with mss() as screenshotter: |
13 | | - # ... |
14 | 12 |
|
15 | | - |
16 | | -Or import the good one (choose one):: |
| 13 | +Or import the good one:: |
17 | 14 |
|
18 | 15 | # MacOS X |
19 | | - from mss.darwin import MSS |
| 16 | + from mss.darwin import MSS as mss |
20 | 17 |
|
21 | 18 | # GNU/Linux |
22 | | - from mss.linux import MSS |
| 19 | + from mss.linux import MSS as mss |
23 | 20 |
|
24 | 21 | # Microsoft Windows |
25 | | - from mss.windows import MSS |
26 | | - |
27 | | - with MSS() as screenshotter: |
28 | | - # ... |
29 | | - |
30 | | - |
31 | | -Of course, you can use it the old way:: |
32 | | - |
33 | | - from mss import mss |
34 | | - # or from mss.linux import MSS as mss |
35 | | - |
36 | | - screenshotter = mss() |
37 | | - |
38 | | - |
39 | | -Examples |
40 | | --------- |
41 | | - |
42 | | -One screenshot per monitor:: |
43 | | - |
44 | | - for filename in screenshotter.save(): |
45 | | - print(filename) |
| 22 | + from mss.windows import MSS as mss |
46 | 23 |
|
47 | | -Screenshot of the monitor 1:: |
48 | 24 |
|
49 | | - print(next(screenshotter.save(mon=1))) |
| 25 | +Instance |
| 26 | +======== |
50 | 27 |
|
51 | | -Screenshot of the monitor 1, with callback:: |
| 28 | +So the module can be used as simply as:: |
52 | 29 |
|
53 | | - def on_exists(fname): |
54 | | - ''' Callback example when we try to overwrite an existing |
55 | | - screenshot. |
56 | | - ''' |
57 | | - |
58 | | - from os import rename |
59 | | - from os.path import isfile |
60 | | - |
61 | | - if isfile(fname): |
62 | | - newfile = fname + '.old' |
63 | | - print('{0} -> {1}'.format(fname, newfile)) |
64 | | - rename(fname, newfile) |
65 | | - return True |
66 | | - |
67 | | - print(next(screenshotter.save(mon=1, callback=on_exists))) |
68 | | - |
69 | | -A screenshot to grab them all:: |
70 | | - |
71 | | - print(next(screenshotter.save(mon=-1, output='fullscreen.png'))) |
72 | | - |
73 | | - |
74 | | -Into the Python's console |
75 | | -------------------------- |
76 | | - |
77 | | -.. code:: python |
78 | | -
|
79 | | - >>> from mss import mss |
80 | | - >>> sct = mss(display=':0') |
81 | | -
|
82 | | - # Retrieve monitors informations |
83 | | - >>> displays = sct.enum_display_monitors() |
84 | | - >>> displays |
85 | | - [{'width': 1920, 'top': 0, 'height': 1080, 'left': 0}, {'width': 1920, 'top': 0, 'height': 1080, 'left': 0}] |
86 | | - # You can access monitors list via `monitors`: |
87 | | - >>> sct.monitors |
88 | | - [{'width': 1920, 'top': 0, 'height': 1080, 'left': 0}, {'width': 1920, 'top': 0, 'height': 1080, 'left': 0}] |
89 | | -
|
90 | | - # Retrieve pixels from the first monitor |
91 | | - >>> pixels = sct.get_pixels(displays[1]) |
92 | | - >>> pixels |
93 | | - <ctypes.c_char_Array_6220800 object at 0x7fe82e9007a0> |
94 | | - # You can access pixels data via `image`: |
95 | | - >>> sct.image |
96 | | - <ctypes.c_char_Array_6220800 object at 0x7fe82e9007a0> |
| 30 | + with mss() as screenshotter: |
| 31 | + # ... |
97 | 32 |
|
98 | | - # Save pixels to a PNG file: option 1 |
99 | | - >>> files = sct.save(mon=1) |
100 | | - >>> next(files) |
101 | | - 'monitor-1.png' |
102 | | - >>> next(files) |
103 | | - Traceback (most recent call last): |
104 | | - File "<stdin>", line 1, in <module> |
105 | | - StopIteration |
| 33 | +Or:: |
106 | 34 |
|
107 | | - # Save pixels to a PNG file: option 2 |
108 | | - >>> mon = displays[1] |
109 | | - >>> sct.to_png(data=pixels, width=mon['width'], height=mon['height'], output='monitor-1.png') |
| 35 | + screenshotter = mss() |
0 commit comments