Python implements analog keys, auto-flip to see U17 comics

Source: Internet
Author: User
Python
For the Windows platform
Using the Win32gui,win32api,win32con Package

simu_read.py

Copy the Code code as follows:


#-*-Coding=utf-8-*-
'''
Analog button Flip
Usage:python simu_read.py 10 1.5
10 means 10 pages, 1.5 means that the time interval of pressing PGDN in one page is 1.5s
One page PgDn 3 times, then press → to turn to the next page
Open the browser to U17 to see the comic, then start the program, and then cut back to U17
You can automatically turn the page to see the comics.
Fun-only, understanding Python analog keys
'''
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 are none and not Y are 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":, ' 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 is in the range [1,10000] '
Sys.exit (-1)
If interval < 0.1 or interval > 60:
print ' interval should is 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 was 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

The above is the whole content of this article to share, I hope you can enjoy.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.