회사 컴퓨터는 윈도우 화면 꺼짐 시간 조정이 불가능하고 프로그램으로 5분마다 화면 보호기가 작동한다.
그래서 5분마다 윈도우 PW를 입력해야하고, 윈도우 PW 또한 암호화 정책이 걸려있어 긴 패스워드가 요구된다.
이게 너무 귀찮아서 python으로 매크로를 만들어봤다.
pyinstaller
- exe 파일로 만들기 위함
pyautogui
- 위 라이브러리 사용으로 키보드 마우스 조작을 할 수 있다.
time
random
import pyautogui
import time
import random
while True:
pyautogui.FAILSAFE = True
screenW, screenH = pyautogui.size()
temp_x, temp_y = pyautogui.position()
time.sleep(145)
current_x, current_y = pyautogui.position()
if temp_x == current_x and temp_y == current_y:
ran_w = random.randint(1, screenW)
ran_h = random.randint(1, screenH)
pyautogui.moveTo(ran_w, ran_h, 0.3)
pyautogui.typewrite(" ", 1)
# print(temp_x, temp_y)
# print(current_x, current_y)
pyautogui.FAILSAFE = True
- 오류가 떠도 무시하고 실행한다
pyautogui.FAILSAFE = True
- 오류가 떠도 무시하고 실행한다
screenW, screenH = pyautogui.size() temp_x, temp_y = pyautogui.position() time.sleep(145) current_x, current_y = pyautogui.position()
- pyautogui.size()
-> 화면 size를 x, y 좌표값으로 반환함- pyautogui.position()
-> 마우스 x, y 좌표값을 반환함
if temp_x == current_x and temp_y == current_y: ran_w = random.randint(1, screenW) ran_h = random.randint(1, screenH) pyautogui.moveTo(ran_w, ran_h, 0.3) pyautogui.typewrite(" ", 1)
- temp_x, temp_y 에 마우스 좌표를 저장 후
145초가 지나도 current_x, current_y 현재 x, y 좌표와 같으면
마우스와 typewite() 함수로 spacebar를 한번 친다.
pyinstaller -w -F "파이썬 파일 명".py
https://github.com/Carrotww/Carrot_pyauto/tree/main/Carrot_auto_screen/dist