-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyautogui_screenshot.py
81 lines (58 loc) · 2.29 KB
/
pyautogui_screenshot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# 202401 - Python 3.12.0
# 4.12 - Tirando prints da tela
import pyautogui
import time
import logging
import logging.config
import keyboard
# configurando logging:
logging.config.fileConfig(fname='config.ini', disable_existing_loggers=False)
logger = logging.getLogger(__name__)
def screenshot_calculadora():
logging.info('INICIO: screenshot calculadora.')
try:
def largura_altura():
# coordenadas do screenshot
regiao_inicial = [1457, 188]
regiao_final = [1855, 851]
regiao = []
# calcula largura e altura do screenshot
largura = regiao_final[0] - regiao_inicial[0]
altura = regiao_final[1] - regiao_inicial[1]
# coordenadas do screenshot para argumento 'region'
regiao.extend([regiao_inicial[0], regiao_inicial[1], largura, altura])
logging.info('Coordenadas do screenshot inseridas.')
return regiao
regiao = largura_altura()
pyautogui.screenshot('assets/screenshot1.jpg', region=regiao)
logging.info('Screenshot salvo.')
except Exception as e:
logging.error(f"Erro ao tirar screenshot da calculadora: {e}")
# screenshot_calculadora()
def screenshot_notepad():
logging.info('INICIO: screenshot notepad.')
try:
def abrindo_notepad(frase):
pyautogui.hotkey('win')
pyautogui.click(955, 159, duration=.5)
pyautogui.typewrite('notepad')
time.sleep(1)
pyautogui.hotkey('enter')
time.sleep(2)
pyautogui.hotkey('ctrl', 'n')
time.sleep(1)
keyboard.write(frase, delay=.1)
logging.info('Notepad aberto.')
abrindo_notepad('42')
def salvando_screenshot():
# obtendo janela ativa
janela_ativa = pyautogui.getActiveWindow()
# screenshot janela ativa
screenshot = pyautogui.screenshot(region=(janela_ativa.left, janela_ativa.top, janela_ativa.width, janela_ativa.height))
# salvando screenshot
screenshot.save(r'assets/screenshot2.jpg')
logging.info('Screenshot salvo.')
salvando_screenshot()
except Exception as e:
logging.error(f"Erro ao tirar screenshot do notepad: {e}")
screenshot_notepad()