视频1 视频21 视频41 视频61 视频文章1 视频文章21 视频文章41 视频文章61 推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37 推荐39 推荐41 推荐43 推荐45 推荐47 推荐49 关键词1 关键词101 关键词201 关键词301 关键词401 关键词501 关键词601 关键词701 关键词801 关键词901 关键词1001 关键词1101 关键词1201 关键词1301 关键词1401 关键词1501 关键词1601 关键词1701 关键词1801 关键词1901 视频扩展1 视频扩展6 视频扩展11 视频扩展16 文章1 文章201 文章401 文章601 文章801 文章1001 资讯1 资讯501 资讯1001 资讯1501 标签1 标签501 标签1001 关键词1 关键词501 关键词1001 关键词1501 专题2001
python实现模拟按键,自动翻页看u17漫画
2020-11-27 14:31:58 责编:小采
文档


python
适用于windows平台
使用 win32gui,win32api,win32con 包

simu_read.py

代码如下:


#-*- coding=utf-8 -*-
'''
模拟按键翻页
Usage:python simu_read.py 10 1.5
10表示翻10页,1.5表示在一页中按pgdn的时间间隔为1.5s
一页pgdn 3 次,之后按→翻到下一页
把浏览器打开到u17要看的漫画中,之后启动该程序,再切回u17
便可以自动翻页看漫画了。
仅供娱乐,了解python模拟按键
'''
import win32gui,win32api,win32con
from ctypes import *
import time
import threading
import sys
''' # mouse click is not used here ,-> can replace it
def get_cursor_pos():
x,y = win32gui.GetCursorPos()
return (x,y)
def mouse_move(x,y):
windll.user32.SetCursorPos(x, y)
def mouse_click(x=None,y=None):
print 'mouse_click'
if not x is None and not y is None:
mouse_move(x,y)
time.sleep(0.05)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
time.sleep(0.05)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
def test_pos():
for i in range(0,10):
time.sleep(0.5)
print get_cursor_pos()
'''
def key_up(key_num):
win32api.keybd_event(key_num,0,0,0)
win32api.keybd_event(key_num,0,win32con.KEYEVENTF_KEYUP,0)
def init_dict():
dict1 = {"PageDown":34,'RightArrow':39}
return dict1
if __name__ == '__main__':
if len(sys.argv) != 3:
print 'Usage:python simu_read.py '
sys.exit(-1)
try:
pagenum = int(sys.argv[1])
interval = float(sys.argv[2])
except ValueError:
print 'Usage:python simu_read.py '
print ' should be the type of int'
print ' should be the type of float'
sys.exit(-1)
if pagenum < 0 or pagenum > 10000:
print 'pagenum should be in the range [1,10000]'
sys.exit(-1)
if interval < 0.1 or interval > 60:
print 'interval should be in the range [0.1,60]'
sys.exit(-1)
key_dict = init_dict()
stsec = 2
print 'start in '+str(stsec)+' seconds...'
time.sleep(stsec)
for i in range(0,pagenum):
for j in range(0,3):#generally,the height of one page is not more than 3 screensize
print 'PageDown'
key_up(key_dict['PageDown'])
time.sleep(interval)
key_up(key_dict['RightArrow'])
print 'Next page'
time.sleep(interval+0.2)#delay

下载本文
显示全文
专题