前言

现在的电脑族们,在使用电脑的过程中,常常忘记了时间的流逝,要么忙碌在电视剧的观看中,要么忙碌在工作中,要么忙碌在游戏中,往往忽视了对眼睛的正常保护,让眼睛能够在空闲的时候获得足够的休息时间。

我也是其中之一。

但当我发现自己的眼睛的疲劳程度在慢慢增加的时候,对于视力保护的需求也越来越迫切了。

于是,利用自己的小小编程技巧,利用python的简易性,实现了下面的“强制眼睛休息的脚本”,当设定的工作时间结束后,计算机的显示器会被强制关闭,如果用鼠标进行强制唤醒,显示器依然会随后快速关闭,直到设定的休息时间都过去以后,显示器才会开启。

具体实现如下

 """
count down the time to close the display
Create by Zhong Xiewei
"""
import time
import os
import platform work_time = int(raw_input("Enter your work time [min]: "))
break_time = int(raw_input("Enter your break time [min]: "))
break_time = break_time*60
start = raw_input("Do you want start [y/n]: ")
os_str = platform.system() work_stage = 0
while (start == 'y'):
for i in range(work_time):
print 'Remain ', work_time-i, 'min'
time.sleep(60) # During the break time
# the display should always be closed
# if rewake by mouse, it will be closed again
insleep = 1
start_time = time.time()
while (insleep):
if os_str == "Windows":
# Under windows, nircmd should be installed first
# The usage can reference: www.nirsoft.net/utils/nircmd.html
os.system("nircmd.exe monitor off")
elif os_str == "Linux":
os.system("xset dpms force off")
end_time = time.time()
if end_time-start_time > break_time:
insleep = 0 if os_str == "Linux":
os.system("xset dpms force on")
elif os_str == "Windows":
os.system("nircmd.exe monitor on") work_stage = work_stage + 1
print "================\nWork Stage ", work_stage,"\n================\n"
start = raw_input("Do you want continue [y/n]: ")
05-11 13:06