Python自动锁屏–window系统「建议收藏」

Python自动锁屏–window系统「建议收藏」  天天面对着电脑敲代码,你是否忘记了保护视力了,眼睛的度数在上涨,镜片变厚,这是我们期望的么?今天有点空闲时间,写了个Python自动锁屏脚本,使用的是Python2.7,代码如下#coding:utf8importosimporttime#locktime你设置的锁屏周期(单位:s)locktime=1*60*60starttime=int(t…

大家好,又见面了,我是你们的朋友全栈君。

    天天面对着电脑敲代码,你是否忘记了保护视力了,眼睛的度数在上涨,镜片变厚,这是我们期望的么?今天有点空闲时间,写了个Python自动锁屏脚本,使用的是Python 2.7,代码如下

#coding:utf8

import os
import time

#locktime你设置的锁屏周期(单位 : s)
locktime = 1 * 60 * 60
starttime = int(time.time())

def locakMonitor():
	os.system('RunDll32.exe user32.dll,LockWorkStation')

def showWindowMsg(info,btnval,wintitle):
	vbstrcommand = 'mshta vbscript:msgbox('+'"'+info+'"'+","+str(btnval) +","+'"'+wintitle+'"'+")(window.close)"
	#print vbstrcommand
	os.system(vbstrcommand)

def getInput():
	while True:
		input = raw_input('continue lock(y or n):')
		lowerinput = input.lower()
		if 'y' == lowerinput:
			return True
		elif 'n' == lowerinput:
			return False
		else:
			print u'输入错误'
			continue

if __name__ == '__main__':
	while True:
		nowtime = int(time.time())
		time.sleep(1)
		#os.system("mshta vbscript:msgbox("+"cccc" +",64,"+"ccccc"+")(window.close)");
		print 'after ' + str(nowtime - starttime) + 's'
		if(nowtime == starttime + locktime):
			showWindowMsg('lock after 5s',0,'lockinfo')
			print u'5秒后将锁屏,请注意保护视力....'
			time.sleep(5)
			locakMonitor()
			if getInput() == True:
				starttime = int(time.time())
				continue
			else:
				print u'锁屏脚本结束'
				break
			#重置开始时间
			starttime = int(time.time())

  可以自己去设定锁屏周期,运行下脚本,自动锁屏

   修改部分拼写错误,锁屏时间计算问题,窗口弹出不显示,直接发出声音

   version2.0 如下

   

#coding:utf8

import os
import time
import winsound
import webbrowser
 
#locktime你设置的锁屏周期(单位 : s)
locktime = 1 * 15
starttime = int(time.time())

def lockMonitor():
	os.system('RunDll32.exe user32.dll,LockWorkStation')
 
def showWindowMsg(info,btnval,wintitle):
	vbstrcommand = 'mshta vbscript:msgbox('+'"'+info+'"'+","+str(btnval) +","+'"'+wintitle+'"'+")(window.close)"
	#print vbstrcommand
	os.system(vbstrcommand)
 
def getInput():
	while True:
		input = raw_input('continue lock(y or n):')
		lowerinput = input.lower()
		if 'y' == lowerinput:
			return True
		elif 'n' == lowerinput:
			return False
		else:
			print u'输入错误'
			continue
 
if __name__ == '__main__':
	while True:
		time.sleep(1)
		nowtime = int(time.time())
		#os.system("mshta vbscript:msgbox("+"cccc" +",64,"+"ccccc"+")(window.close)");
		print 'running ' + str(nowtime - starttime) + 's'
		if nowtime >= (starttime + locktime):
			#窗口显示看不到,发出声音
			#showWindowMsg('lock after 5s',0,'lockinfo')
			print u'5秒后将锁屏,请注意保护视力....'
			winsound.Beep(600,5000)
			#webbrowser.open('C:/Users/chengdu/Desktop/FILE/1.html')
			#time.sleep(5)
			lockMonitor()
			if getInput() == True:
				starttime = int(time.time())
				continue
			else:
				print u'锁屏脚本结束'
				break


 

 Python3版本

#coding:utf8

import os
import time
import winsound
import webbrowser
 
#locktime你设置的锁屏周期(单位 : s)
locktime = 1 * 15
starttime = int(time.time())

def lockMonitor():
	os.system('RunDll32.exe user32.dll,LockWorkStation')
 
def showWindowMsg(info,btnval,wintitle):
	vbstrcommand = 'mshta vbscript:msgbox('+'"'+info+'"'+","+str(btnval) +","+'"'+wintitle+'"'+")(window.close)"
	#print vbstrcommand
	os.system(vbstrcommand)
 
def getInput():
	while True:
		kinput = input('continue running(y or n):')
		lowerinput = kinput.lower()
		if 'y' == lowerinput:
			return True
		elif 'n' == lowerinput:
			return False
		else:
			print (u'输入错误')
			continue
 
if __name__ == '__main__':
	while True:
		time.sleep(1)
		nowtime = int(time.time())
		#os.system("mshta vbscript:msgbox("+"cccc" +",64,"+"ccccc"+")(window.close)");
		print ('running ' + str(nowtime - starttime) + 's')
		if nowtime >= (starttime + locktime):
			#窗口显示看不到,发出声音
			#showWindowMsg('lock after 5s',0,'lockinfo')
			print (u'5秒后将锁屏,请注意保护视力....')
			winsound.Beep(600,5000)
			#webbrowser.open('C:/Users/chengdu/Desktop/FILE/1.html')
			#time.sleep(5)
			lockMonitor()
			if getInput() == True:
				starttime = int(time.time())
				continue
			else:
				print (u'锁屏脚本结束')
				break

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/162761.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 软件测试相关知识_软件测试期末考试知识点

    软件测试相关知识_软件测试期末考试知识点软件测试是软件生存周期中必不可少的环节,软件的典型生存周期可以用下图来形容:软件测试的目的是尽可能早的发现软件缺陷并确保其得以修复,因此软件测试是提高软件质量的重要手段,大量的经验实践证明,软件测试越早参与到软件开发过程中,开发出来的软件质量相对越高,时间和物力也越经济。根据软件工程的基本理论,多模块程序的测试共包括以下4个层次:…

    2022年9月1日
  • gFortran的使用

    gFortran的使用Fortran编程中相关文件后缀.a静态库(archive).f,.for,.FOR.ftn*,.f90*,.f95*,.f03*Fortran源代码(不需编译预处理).F,.fpp,.FPP.FTN*,.F90*,.F95*,.F03*Fortran源代码(需要编译预处理).rFortran源代码(需要…

    2022年10月30日
  • js查询手机号码归属地[通俗易懂]

    js查询手机号码归属地[通俗易懂]js查询手机号码归属地

    2022年7月22日
  • python视频网站项目_价值2400元的python全栈开发系列Flask Python Web 网站编程视频

    python视频网站项目_价值2400元的python全栈开发系列Flask Python Web 网站编程视频2e/b4F1c’H$D!X价值2400元的python全栈开发系列FlaskPythonWeb网站编程视频-优品课堂’z3_1Y7]6j4z#p#r#g*A9e8k5h’V7w,M$f6C6X*e”J2N课程目录:%v2_&D+L5_)a$L;C.C01-计算机基础常识.mp49T,_9X9p+y4B7…

    2022年5月7日
  • Ubuntu16.04 环境 Kubeedge安装「建议收藏」

    Ubuntu16.04 环境 Kubeedge安装「建议收藏」前期准备换源#备份sudocp/etc/apt/sources.list/etc/apt/sources.list.bak#更新sources.listsudotee/etc/apt/sources.list<<-‘EOF’debhttp://mirrors.aliyun.com/ubuntu/xenialmaindeb-srchttp://mirrors.aliyun.com/ubuntu/xenialmaindebhttp://mirr

    2022年7月21日
  • Java的常用输入输出语句

    Java的常用输入输出语句一、概述  输入输出可以说是计算机的基本功能。作为一种语言体系,java中主要按照流(stream)的模式来实现。其中数据的流向是按照计算机的方向确定的,流入计算机的数据流叫做输入流(inputStream),由计算机发出的数据流叫做输出流(outputStream)。Java语言体系中,对数据流的主要操作都封装在java.io包中,通过java.io包中的类可以实现计算机对数据的输入、输出操作…

    2022年5月26日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号