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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 区块链每日快讯(0122)[通俗易懂]

    区块链每日快讯(0122)

    2022年3月13日
    55
  • 1分钟搞定 OneNote自己账号扩容到15G永久免费空间「建议收藏」

    1分钟搞定 OneNote自己账号扩容到15G永久免费空间「建议收藏」本文是众多使用技巧中其中的一篇,全部使用技巧点击链接查看,或直接查看本专栏其他文章,保证你收获满满我主页中的思维导图中内容大多从我的笔记中整理而来,相应技巧可在笔记中查找原题,有兴趣的可以去我的主页了解更多计算机学科的精品思维导图整理本文可以转载,但请注明来处,觉得整理的不错的小伙伴可以点赞关注支持一下哦!本文提到的所有软件和工具,可关注公众号一起学计算机点击资源获取获得感觉作者写的不错的,别忘了点赞关注加收藏哦(一键三连)!你的支持会带给我…

    2025年10月13日
    5
  • 竞争性需求分析

    竞争性需求分析

    2021年11月18日
    48
  • 数据库建模

    1)定义:在设计数据库时,对现实世界进行分析、抽象、并从中找出内在联系,进而确定数据库的结构,这一过程就称为数据库建模。2)作用:1.模型能准确表达设计意图,更易于进行技术交流。2.模型可以用来高效地生产代码、脚本、技术文档,可以做到“一处改动,多处同步”的效果。3.模型驱动的开发能使开发过程保持一致性,提高开发人员的效率,而且能保持我们的设计模型能被准确的实现而不产生歪曲。

    2022年4月8日
    194
  • docker命令大全

    docker命令大全1、启动dockersystemctlstartdocker2、

    2022年5月16日
    47
  • flex java教程_java入门推荐

    flex java教程_java入门推荐http://blogs.infosupport.com/flash-builder-4-the-easiest-way-to-create-a-combined-flex-java-project/http://bdk82924.iteye.com/blog/1067285整整一年之后http://hi.baidu.com/amauri3389/item/88ec1ed

    2022年8月30日
    2

发表回复

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

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