Chinaunix首页 | 论坛 | 博客
  • 博客访问: 473345
  • 博文数量: 51
  • 博客积分: 1056
  • 博客等级: 少尉
  • 技术积分: 676
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-10 22:53
文章存档

2018年(2)

2017年(1)

2013年(2)

2012年(9)

2011年(36)

2010年(1)

分类: Python/Ruby

2017-10-07 23:08:52

域控云桌面   每隔10分钟不敲鼠标键盘必锁屏。每天疲于输入密码,不胜其烦。
假期怒学python  ,实现检查系统一段时间没有敲鼠标键盘,则自动按2下num键,阻止防止系统锁屏。
为啥是num键? 因为实在找不到啥别的人畜无害的按键了。哪怕是ScrollLock也是有可能捣乱的。
打包成win7 64位 exe  下载地址:


源码奉上,可自行打包
不要在意代码风格路子野

点击(此处)折叠或打开

  1. #打包exe命令:pyinstaller -.\tool.ico -F test.py

  2. import py_compile
  3. from ctypes import *
  4. from ctypes import Structure, windll, c_uint, sizeof, byref
  5. import time
  6. import os
  7. import win32api
  8. import win32con
  9. import configparser

  10. class LASTINPUTINFO(Structure):
  11.     _fields_ = [('cbSize', c_uint), ('dwTime',c_uint)]
  12. #python调用GetLastInputInfo
  13. def get_idle_duration():
  14.     lastInputInfo = LASTINPUTINFO()
  15.     lastInputInfo.cbSize = sizeof(lastInputInfo)
  16.     windll.user32.GetLastInputInfo(byref(lastInputInfo))
  17.     millis = windll.kernel32.GetTickCount()- lastInputInfo.dwTime
  18.     return millis / 1000.0


  19. def get_mouse_point():
  20.     po = POINT()
  21.     windll.user32.GetCursorPos(byref(po))
  22.     return po

  23. class POINT(Structure):
  24.     _fields_ = [("x", c_ulong),("y", c_ulong)]

  25. filename = 'tool.ini'
  26. mydelay=60*10-20
  27. conf = configparser.ConfigParser()
  28. print("锁屏汪 V1.00 版 for win7-x64")
  29. print("防止10分钟锁屏")
  30. #通过配置文件的方式配置mydelay 弃用
  31. if os.path.exists(filename):
  32. # conf.read(filename)
  33. if conf.has_option("config", "delay"):
  34. # mydelay=conf.get("config", "delay")
  35. else:
  36. # conf.add_section('config') # 添加section
  37. # conf.set('config', 'delay', str(mydelay)) # 添加值
  38. # fp = open(filename, "w")
  39. # conf.write(fp)
  40. print(fp.name)
  41. # fp.close()
  42. print("系统无键鼠输入"+str(mydelay),"秒后,将自动模拟按下2次num按键")
  43. while True:
  44.     #移动鼠标的方式不顶用 还是会锁屏
  45.     # curpo = get_mouse_point()
  46.     # print("x =",int(curpo.x), "y =",int(curpo.y))
  47.     # if i==0:
  48.     # windll.user32.SetCursorPos(int(curpo.x), int(curpo.y) + 1)
  49.     # i=1
  50.     # else:
  51.     # windll.user32.SetCursorPos(int(curpo.x), int(curpo.y) - 1)
  52.     # i=0

  53.     # print(get_idle_duration())
  54.     if get_idle_duration() >= int(mydelay):
  55.         print(get_idle_duration())
  56.         win32api.keybd_event(144, 0, 0, 0) # num键位码是144
  57.         win32api.keybd_event(144, 0, win32con.KEYEVENTF_KEYUP, 0) # 释放按键
  58.         time.sleep(0.1)
  59.         win32api.keybd_event(144, 0, 0, 0) # num键位码是144
  60.         win32api.keybd_event(144, 0, win32con.KEYEVENTF_KEYUP, 0) # 释放按键
  61.     time.sleep(10)#每隔10s检查一次
  62.    
阅读(663) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

liuhuahan79982017-11-27 16:59:25

徐老师还是那么的厉害啊