現在的電腦族們,在使用電腦的過程中,常常忘記了時間的流逝,要么忙碌在電視劇的觀看中,要么忙碌在工作中,要么忙碌在游戲中,往往忽視了對眼睛的正常保護,讓眼睛能夠在空閑的時候獲得足夠的休息時間。
我也是其中之一。
但當我發現自己的眼睛的疲勞程度在慢慢增加的時候,對于視力保護的需求也越來越迫切了。
于是,利用自己的小小編程技巧,利用python的簡易性,實現了下面的“強制眼睛休息的腳本”,當設定的工作時間結束后,計算機的顯示器會被強制關閉,如果用鼠標進行強制喚醒,顯示器依然會隨后快速關閉,直到設定的休息時間都過去以后,顯示器才會開啟。
1 """ 2 count down the time to close the display 3 Create by Zhong Xiewei 4 """ 5 import time 6 import os 7 import platform 8 9 work_time = int(raw_input("Enter your work time [min]: "))10 break_time = int(raw_input("Enter your break time [min]: "))11 break_time = break_time*6012 start = raw_input("Do you want start [y/n]: ")13 os_str = platform.system()14 15 work_stage = 016 while (start == 'y'):17 for i in range(work_time):18 PRint 'Remain ', work_time-i, 'min'19 time.sleep(60)20 21 # During the break time22 # the display should always be closed23 # if rewake by mouse, it will be closed again24 insleep = 125 start_time = time.time()26 while (insleep):27 if os_str == "Windows":28 # Under windows, nircmd should be installed first29 # The usage can reference: www.nirsoft.net/utils/nircmd.html30 os.system("nircmd.exe monitor off")31 elif os_str == "linux":32 os.system("xset dpms force off")33 end_time = time.time()34 if end_time-start_time > break_time:35 insleep = 036 37 if os_str == "Linux":38 os.system("xset dpms force on")39 elif os_str == "Windows":40 os.system("nircmd.exe monitor on")41 42 work_stage = work_stage + 143 print "================/nWork Stage ", work_stage,"/n================/n"44 start = raw_input("Do you want continue [y/n]: ")
新聞熱點
疑難解答