회사 화면 보호기 방지 매크로

유형석·2022년 8월 17일
0

python

목록 보기
3/4
post-thumbnail

회사 컴퓨터는 윈도우 화면 꺼짐 시간 조정이 불가능하고 프로그램으로 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를 한번 친다.

typewite() 함수 사용 이유

  • 회사 프로그램이 어떤식으로 자리 비움을 감지하는지 모르지만
    초기에 마우스 동작만 주었고, 이 방식으로는 화면 보호기 생성을 막을 수 없어 키보드 입력도 주었다.

exe 파일로 만들기

  • pyinstaller 라이브러리를 받고
pyinstaller -w -F "파이썬 파일 명".py

Git hub exe파일 주소

https://github.com/Carrotww/Carrot_pyauto/tree/main/Carrot_auto_screen/dist

profile
Carrot_hyeong

0개의 댓글