Jun-03-2019, 06:58 AM
I just spent 2.5 hours straight on this and it works very well. I got the inspiration from a youtuber names Code Bullet. Anyways it could use a few improvements. Here is a list of stuff to be improved:
- In detect I find out if columnCount is past a certain number. I was doing this because it was becoming off centered and clicking more to the right. Does anyone know why and how, I can fix it. This would really speed up the code.
- Compacting the while loop in main and the detect function to speed things up.
- Any other suggestions are accepted
Note: the timer class is to slowly increase the y offset for the mouse click to match up with the fast keys.
If you wanna see the 2.5 hour long video of me creating it - https://youtu.be/DNo451FWvKs - you probably won't click on this link...
One last thing. If you are reading this before it has been up for 50 minutes, the link probably doesn't work. In case you were wondering, yes the video is going to take almost an hour to upload.
- In detect I find out if columnCount is past a certain number. I was doing this because it was becoming off centered and clicking more to the right. Does anyone know why and how, I can fix it. This would really speed up the code.
- Compacting the while loop in main and the detect function to speed things up.
- Any other suggestions are accepted
Note: the timer class is to slowly increase the y offset for the mouse click to match up with the fast keys.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
import time import win32con, win32api, win32gui from PIL import ImageGrab import cv2 import keyboard import threading ''' Box - 362, 89, 929, 864 Note - Scroll down once _, _, mousePos = win32gui.GetCursorInfo() ''' columnDict = { 'left' : ( 100 , 0 , 101 , 775 ), 'left-middle' : ( 200 , 0 , 201 , 775 ), 'right-middle' : ( 350 , 0 , 351 , 775 ), 'right' : ( 500 , 0 , 501 , 775 )} def click(x,y): win32api.SetCursorPos((x,y)) win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y, 0 , 0 ) win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y, 0 , 0 ) class timer(): def __init__( self ): self .time = 0 def decrease( self ): while True : time.sleep( 2 ) self .time + = 1 def detect(t): img = cv2.imread( 'MagicTiles.png' ) for row in img: columnCount = 0 for column in row: columnCount + = 1 if column[ 0 ] = = 0 and column[ 1 ] = = 0 and column[ 2 ] = = 0 or column[ 0 ] in range ( 10 , 30 ): if keyboard.is_pressed( 's' ): return False if columnCount > = 300 : columnCount - = 100 if columnCount > = 200 : columnCount - = 50 elif columnCount > = 100 : columnCount - = 25 click(columnCount + 396 , 350 + t.time) return True return True def main(): time.sleep( 3 ) click( 700 , 500 ) looping = True t = timer() thread = threading.Thread(target = t.decrease) thread.start() while looping: ImageGrab.grab(( 396 , 400 , 896 , 401 )).save( 'MagicTiles.png' , 'PNG' ) looping = detect(t) if keyboard.is_pressed( 's' ): looping = False if __name__ = = '__main__' : main() |
One last thing. If you are reading this before it has been up for 50 minutes, the link probably doesn't work. In case you were wondering, yes the video is going to take almost an hour to upload.