Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # yt_pl_autoclicker.py
- # Intended to Organize Youtube Playlists VIA Windows --
- # In Being Rushed. Might Still Have A Few Odd Conflicts
- from Tkinter import *
- from ctypes import windll, Structure, c_ulong, byref
- import PIL.ImageGrab
- import time
- root = Tk()
- root.title("AutoClicker")
- root.resizable(width=FALSE, height=FALSE)
- mouse = windll.user32
- state = False
- clicked = 0
- speed = StringVar()
- speed.set(3)
- mainframe = Frame(root)
- mainframe.grid(padx=5, pady=5)
- def StateFalse():
- global state
- state = False
- def StateTrue():
- global state, clicked
- if not state:
- clicked = 0
- state = time.time()-4
- 0
- speedLabel = Label(mainframe, text="Click interval\n(in seconds)").grid(column=1, row=2, sticky=W)
- speedEntry = Entry(mainframe, textvariable=speed, width=5).grid(column=2, row=2)
- startButton = Button(mainframe, text="Start", width=10, command=StateTrue).grid(column=1, row=3,columnspan=2,sticky=W)
- stopButton = Button(mainframe, text="Stop", width=10, command=StateFalse).grid(column=2, row=3, columnspan=2,sticky=E)
- """It simulates the mouse"""
- MOUSEEVENTF_MOVE = 0x0001 # mouse move
- MOUSEEVENTF_LEFTDOWN = 0x0002 # left button down
- MOUSEEVENTF_LEFTUP = 0x0004 # left button up
- MOUSEEVENTF_RIGHTDOWN = 0x0008 # right button down
- MOUSEEVENTF_RIGHTUP = 0x0010 # right button up
- MOUSEEVENTF_MIDDLEDOWN = 0x0020 # middle button down
- MOUSEEVENTF_MIDDLEUP = 0x0040 # middle button up
- MOUSEEVENTF_WHEEL = 0x0800 # wheel button rolled
- MOUSEEVENTF_ABSOLUTE = 0x8000 # absolute move
- SM_CXSCREEN = 0
- SM_CYSCREEN = 1
- VK_NEXT = b'0x22' # PAGE DOWN key
- import ctypes
- LONG = ctypes.c_long
- DWORD = ctypes.c_ulong
- ULONG_PTR = ctypes.POINTER(DWORD)
- WORD = ctypes.c_ushort
- INPUT_MOUSE = 0
- INPUT_KEYBOARD = 1
- INPUT_HARDWARE = 2
- KEYEVENTF_EXTENDEDKEY = 0x0001
- KEYEVENTF_KEYUP = 0x0002
- KEYEVENTF_SCANCODE = 0x0008
- KEYEVENTF_UNICODE = 0x0004
- class MOUSEINPUT(ctypes.Structure):
- _fields_ = (('dx', LONG),
- ('dy', LONG),
- ('mouseData', DWORD),
- ('dwFlags', DWORD),
- ('time', DWORD),
- ('dwExtraInfo', ULONG_PTR))
- class KEYBDINPUT(ctypes.Structure):
- _fields_ = (('wVk', WORD),
- ('wScan', WORD),
- ('dwFlags', DWORD),
- ('time', DWORD),
- ('dwExtraInfo', ULONG_PTR))
- class HARDWAREINPUT(ctypes.Structure):
- _fields_ = (('uMsg', DWORD),
- ('wParamL', WORD),
- ('wParamH', WORD))
- class _INPUTunion(ctypes.Union):
- _fields_ = (('mi', MOUSEINPUT),
- ('ki', KEYBDINPUT),
- ('hi', HARDWAREINPUT))
- class INPUT(ctypes.Structure):
- _fields_ = (('type', DWORD),
- ('union', _INPUTunion))
- def send_input(*inputs):
- nInputs = len(inputs)
- LPINPUT = INPUT * nInputs
- pInputs = LPINPUT(*inputs)
- cbSize = ctypes.c_int(ctypes.sizeof(INPUT))
- return ctypes.windll.user32.SendInput(nInputs, pInputs, cbSize)
- def input_structure(structure):
- if isinstance(structure, MOUSEINPUT):
- return INPUT(INPUT_MOUSE, _INPUTunion(mi=structure))
- if isinstance(structure, KEYBDINPUT):
- return INPUT(INPUT_KEYBOARD, _INPUTunion(ki=structure))
- if isinstance(structure, HARDWAREINPUT):
- return INPUT(INPUT_HARDWARE, _INPUTunion(hi=structure))
- raise TypeError('Cannot create INPUT structure!')
- def keyboard_input(code, flags):
- return KEYBDINPUT(0, code, flags, 0, None)
- def keyboard_event(code, flags=KEYEVENTF_UNICODE):
- return input_structure(keyboard_input(code, flags))
- def press(character):
- code = ord(character)
- send_input(keyboard_event(code))
- send_input(keyboard_event(code, KEYEVENTF_KEYUP))
- 0
- class POINT(Structure):
- _fields_ = [("x", c_ulong), ("y", c_ulong)]
- 0
- def MouseClick(x,y):
- try:
- windll.user32.SetCursorPos(x,y)
- except:
- return
- mouse.mouse_event(2, 0, 0, 0, 0) # left mouse button down
- mouse.mouse_event(4, 0, 0, 0, 0) # left mouse button up
- windll.user32.SetCursorPos(pt.x,pt.y)
- 0
- def scan(x,y,rgb=0):
- if not clicked:
- pixel = PIL.ImageGrab.grab(bbox=(pt.x,pt.y,pt.x+1,pt.y+1)).load()[0,0]
- print "Mouse Position:", pt.x,pt.y
- print "RGB:", pixel
- print
- else:
- print "Scan Position:", x,y
- x0,y0 = 1312,106
- pixel = PIL.ImageGrab.grab(bbox=(x0,y0,x0+1,y0+1)).load()[0,0]
- if pixel == (191, 54, 12):
- print '+'*40
- if cv.nav > 2:
- cv.nav = 1
- elif pixel == (38, 11, 2):
- print '-'*40
- cv.nav = 3
- else:
- return
- if cv.nav == 3:
- cv.nav = 1
- screen = PIL.ImageGrab.grab(bbox=(x-5,y-5,x+5,y+5)).load()
- cbox = []
- yy = 0
- for yz in range(y-3,y+3):
- xx = 0
- for xz in range(x-3,x+3):
- cbox += [screen[xx,yy]]
- xx += 1
- yy += 1
- if (6,95,212) in cbox:
- MouseClick(400,700) # for skipping to next video
- return
- print '!'*30,'selected!'
- MouseClick(x,y)
- else:
- for y2 in range(y,y+300,10):
- windll.user32.SetCursorPos(x,y2)
- time.sleep(0.002) # to make sure any changes are captured
- screen = PIL.ImageGrab.grab(bbox=(x-3,y2-3,x+3,y2+3)).load()
- data = {}
- yy = 0
- for y0 in range(y2-3,y2+3):
- xx = 0
- for x0 in range(x-3,x+3):
- data[x0,y0] = screen[xx,yy]
- xx += 1
- yy += 1
- if rgb:
- d = [data[z] for z in data]
- if tuple(rgb) in d:
- print '*** Found ***'
- MouseClick(x,y2)
- cv.nav += 1
- return
- cv.nav = 1
- print '...'
- 0
- class Cv(): 0
- cv = Cv()
- cv.nav = 1
- ymin = 150
- ymax = 720
- page_scroll = 1380,704
- wait = 1
- y = 0
- print ">>> Auto Clicker --"
- print ">>> This Version Is Intended To Organize Youtube Playlists VIA Windows"
- while True:
- if state:
- if not clicked:
- clicked = 1
- print ">>> Auto Clicker -- Activated..."
- if time.time() > state:
- pt = POINT()
- windll.user32.GetCursorPos(byref(pt))
- state = time.time()+4
- if cv.nav == 1:
- scan(1306,100+y,[96]*3) # video menu
- elif cv.nav == 2:
- scan(1045,120+y,[144]*3) # video menu > save to playlist
- elif cv.nav == 3:
- scan(582,300)
- 0 # scan(582,258,(6,95,212)) # ensure watchlist is deselect
- y += 100
- print 'X'*30,y
- if y > 499:
- print '--- PAGE SCROLL ---'
- MouseClick(400,700) # added measure to avoid scrolling the pop-up
- windll.user32.keybd_event(0x22,0,0,0) # PAGEDOWN press
- windll.user32.keybd_event(0x22,0,0x0002,0) # PAGEDOWN release
- y = 0
- windll.user32.SetCursorPos(pt.x,pt.y)
- print "cv.nav:", cv.nav
- else:
- if clicked:
- print ">>> Auto Clicker -- Stopped"
- clicked = 0
- if time.time() > wait:
- pt = POINT()
- windll.user32.GetCursorPos(byref(pt))
- wait = time.time()+3
- scan(pt.x,pt.y)
- try:
- root.update()
- except:
- print ">>> Auto Clicker -- Exited"
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement