Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- urllib
- pandas
- python
- node.js
- 리눅스
- Linux
- 유니티
- 날짜
- Unity
- ubuntu
- MySQL
- 다이어트
- 함수
- PER
- MS-SQL
- IOS
- GIT
- 맛집
- ASP
- mssql
- javascript
- Excel
- port
- sqlite
- PyQt5
- PyQt
- swift
- 라즈베리파이
- tensorflow
- flutter
Archives
아미(아름다운미소)
화면보호기 본문
from pynput import keyboard, mouse
from pynput.keyboard import Controller, Key
import threading
import time
from datetime import datetime
import ctypes
import os
import platform
# 설정
IDLE_TIME_LIMIT = 300 # 5분 이상 비활동 시
CHECK_INTERVAL = 10 # 활동 체크 주기
keyboard_controller = Controller()
last_activity_time = time.time()
# 사용자 입력 감지 핸들러
def on_input_activity(event):
global last_activity_time
last_activity_time = time.time()
# 화면보호기 방지를 위한 Shift 입력
def prevent_sleep_with_key():
now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print(f"[{now}] [INFO] 활동 없음: Shift 입력 시뮬레이션")
keyboard_controller.press(Key.shift)
time.sleep(0.1)
keyboard_controller.release(Key.shift)
# 화면 잠금
def lock_workstation():
now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print(f"[{now}] 🔒 화면 잠금 실행")
ctypes.windll.user32.LockWorkStation()
# 시스템 종료
def shutdown_system():
if platform.system() == "Windows":
print("[INFO] 시스템 종료 명령 실행")
os.system("shutdown /s /t 0")
# 시스템 재부팅
def reboot_system():
if platform.system() == "Windows":
print("[INFO] 시스템 재부팅 명령 실행")
os.system("shutdown /r /t 0")
# 활동 감지 쓰레드
def monitor_idle():
while True:
idle_time = time.time() - last_activity_time
if idle_time >= IDLE_TIME_LIMIT:
prevent_sleep_with_key()
time.sleep(CHECK_INTERVAL)
# 스케줄러 쓰레드
def scheduled_actions():
triggered = set()
while True:
now = datetime.now()
now_str = now.strftime('%Y-%m-%d %H:%M:%S')
current_time = now.strftime('%H:%M')
weekday = now.weekday() # 0:월 ~ 4:금
# 오전 11시 화면 잠금
if current_time == "11:00" and "lock" not in triggered:
lock_workstation()
triggered.add("lock")
# 오후 5시 종료/재부팅
if current_time == "17:00" and "shutdown" not in triggered:
if weekday in [0, 1, 2, 3]: # 월~목
print(f"[{now_str}] 🔁 월~목: 시스템 재부팅")
reboot_system()
elif weekday == 4: # 금요일
print(f"[{now_str}] ⏹️ 금요일: 시스템 종료")
shutdown_system()
triggered.add("shutdown")
# 자정이 되면 트리거 초기화
if current_time == "00:00":
triggered.clear()
time.sleep(5)
# 입력 감지 리스너 시작
keyboard.Listener(on_press=on_input_activity).start()
mouse.Listener(
on_move=on_input_activity,
on_click=on_input_activity,
on_scroll=on_input_activity
).start()
# 쓰레드 실행
threading.Thread(target=monitor_idle, daemon=True).start()
threading.Thread(target=scheduled_actions, daemon=True).start()
print("🛡️ 활동 감지 + 자동 잠금/재부팅/종료 프로그램 실행 중... (Ctrl+C로 종료)")
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
print("\n[프로그램 수동 종료]")
pyinstaller --noconsole --onefile idle_guard.py
'랭귀지 > pandas' 카테고리의 다른 글
np.select 멀티프로세싱 적용 (0) | 2025.06.12 |
---|---|
Type 변경 (0) | 2025.06.09 |
join (0) | 2025.06.02 |
merge (0) | 2025.05.28 |
object 타입 컬럼을 모두 문자열(str)로 변환 (0) | 2025.05.26 |
Comments