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


相关推荐

  • 从K近邻算法、距离度量谈到KD树、SIFT+BBF算法

    从K近邻算法、距离度量谈到KD树、SIFT+BBF算法从K近邻算法、距离度量谈到KD树、SIFT+BBF算法前言前两日,在微博上说:“到今天为止,我至少亏欠了3篇文章待写:1、KD树;2、神经网络;3、编程艺术第28章。你看到,blog内的文章与你于别处所见的任何都不同。于是,等啊等,等一台电脑,只好等待..”。得益于田,借了我一台电脑(借他电脑的时候,我连表示感谢,他说“能找到工作全靠你的博客,这点儿小忙还说,不地道”,有的时候,稍许感受到

    2022年6月6日
    23
  • ADN中国队参加微软Kinect他赢得了全国比赛三等奖,我们的创意项目与团队Kinect于Naviswork虚拟之旅

    ADN中国队参加微软Kinect他赢得了全国比赛三等奖,我们的创意项目与团队Kinect于Naviswork虚拟之旅

    2022年1月11日
    56
  • scp和rsync命令[通俗易懂]

    scp和rsync命令[通俗易懂]SCP命令(1)scp定义scp可以实现服务器与服务器之间的数据拷贝。(fromserver1toserver2)(2)基本语法scp-r$pdir/$fname$user@$host:$pdir/$fname命令递归要拷贝的文件路径/名称目的地用户@主机:目的地路径/名称(3)基本示例scp-rjdk1.8.0_291/root@hadoop103:opt/modulescp-rroot@hadoop102:/opt/module/*root@h

    2022年8月30日
    3
  • 设计模式之建造者模式

    设计模式之建造者模式

    2021年12月16日
    39
  • spring aop实例讲解_java swing 教程

    spring aop实例讲解_java swing 教程1.SpringAOP是什么?AspectOrientedProgramming:面向切面编程什么时候会出现面向切面编程的需求?按照软件重构的思想,如果多个类中出现重复的代码,就应该考虑定义一个共同的抽象类,将这些共同的代码提取到抽象类中,比如Teacher,Student都有username,那么就可以把username及相关的get、set方法抽取到SysUser中,这种情况,我们称…

    2022年8月11日
    2
  • SVM解释:五、SMO算法

    SVM解释:五、SMO算法SMO算法是JohnC.Platt在1998年提出的。论文的题目是”SequentialMinimalOptimization:AFastAlgorithmforTrainingSupportVectorMachines”。它很快便成为最快的二次规划优化算法,特别是在针对线性SVM和数据稀疏时性能更优。当然了,SMO优越性能的背后是其相当复杂的数学推导,所以,我也把这块最…

    2022年6月24日
    25

发表回复

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

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