python实现模拟按键,自动翻页看u17漫画

yipeiwu_com6年前Python基础

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 <pagenum> <interval>'
        sys.exit(-1)
    try:
        pagenum = int(sys.argv[1])
        interval = float(sys.argv[2])
    except ValueError:
        print 'Usage:python simu_read.py <pagenum> <interval>'
        print '<pagenum> should be the type of int'
        print '<interval> 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
  

以上就是本文分享的全部内容了,希望大家能够喜欢。

相关文章

如何使用 Pylint 来规范 Python 代码风格(来自IBM)

Pylint 是什么 Pylint 是一个 Python 代码分析工具,它分析 Python 代码中的错误,查找不符合代码风格标准(Pylint 默认使用的代码风格是 PEP 8,具体信...

Python实现图片裁剪的两种方式(Pillow和OpenCV)

Python实现图片裁剪的两种方式(Pillow和OpenCV)

在这篇文章里我们聊一下Python实现图片裁剪的两种方式,一种利用了Pillow,还有一种利用了OpenCV。两种方式都需要简单的几行代码,这可能也就是现在Python那么流行的原因吧。...

python使用thrift教程的方法示例

python使用thrift教程的方法示例

一、前言:   Thrift 是一种接口描述语言和二进制通信协议。以前也没接触过,最近有个项目需要建立自动化测试,这个项目之间的微服务都是通过 Thrift 进行通信的,然后写自动化脚本...

Python下的常用下载安装工具pip的安装方法

1、pip下载安装 1.1 pip下载 # wget "https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz#...

Python随机生成手机号、数字的方法详解

本文实例讲述了Python随机生成手机号、数字的方法。分享给大家供大家参考,具体如下: Python随机产生手机号、数字。代码如下: # -*- coding:gbk -*- imp...