This article mainly introduces how to implement analog buttons in python. it is very simple and practical to automatically flip pages to see the Chinese version. if you need them, refer to python.
Applicable to windows platforms
Use win32gui, win32api, and win32con package
Simu_read.py
The code is as follows:
#-*-Coding = utf-8 -*-
'''
Simulate button flip
Usage: python simu_read.py 10 10 1.5
10 indicates turning over 10 pages. 1.5 indicates that the interval between pgdn and pgdn on one page is 1.5 s.
One page pgdn 3 times, then press → to flip to the next page
Open the browser to the cartoon to be viewed by the Chinese site. then start the program and switch back to the Chinese site
You can view the cartoon on the page automatically.
For entertainment only, learn about python analog buttons
'''
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)
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])
Failed T ValueError:
Print 'Usage: python simu_read.py '
Print' Shocould be the type of Int'
Print' Shocould be the type of float'
Sys. exit (-1)
If pagenum <0 or pagenum> 10000:
Print 'pagenum shocould be in the range []'
Sys. exit (-1)
If interval <0.1 or interval> 60:
Print 'interval shoshould 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 'pageid'
Key_up (key_dict ['Page'])
Time. sleep (interval)
Key_up (key_dict ['rightarrow'])
Print 'next page'
Time. sleep (interval + 0.2) # delay
The above is all the content shared in this article. I hope you will like it.