From 66240fe4c0704c5481fe203119367bcac7790e23 Mon Sep 17 00:00:00 2001 From: clarkzjw Date: Tue, 2 Jan 2018 14:59:03 +0800 Subject: + init deps --- .gitignore | 2 ++ requirements.txt | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 .gitignore create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..483de3d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.venv +.idea diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..54b4a43 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +numpy==1.13.3 +opencv-python==3.4.0.12 -- cgit v1.2.3 From f3e1d8caa70829ab3167632905bccaed0b1fb3cd Mon Sep 17 00:00:00 2001 From: clarkzjw Date: Tue, 2 Jan 2018 21:59:04 +0800 Subject: 924 --- bot.py | 111 ++++++++++++++++++------------------------------------- requirements.txt | 83 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+), 76 deletions(-) diff --git a/bot.py b/bot.py index e8f7a3c..f19694a 100644 --- a/bot.py +++ b/bot.py @@ -1,89 +1,48 @@ -import pyautogui as pg -from time import sleep - +import time -def move(_pos, _now): - if _pos == 'left' and _now == 'left': - pg.typewrite(['left']) - pg.typewrite(['left']) - elif _pos == 'left' and _now == 'right': - pg.typewrite(['right']) - pg.typewrite(['right']) - elif _pos == 'right' and _now == 'right': - pg.typewrite(['right']) - pg.typewrite(['right']) - elif _pos == 'right' and _now == 'left': - pg.typewrite(['left']) - pg.typewrite(['left']) - -width, height = pg.size() -width *= 0.5 -pg.moveTo(333, 600) -pg.click() +import mss +import pyautogui as pg +from keyboard import press_and_release +from numpy import array, uint8 -posY = [360, 260, 160] -posX = [276, 398] -q = ['left', 'left', 'left'] +def begin(): + pg.click(440, 900, 2) -im = pg.screenshot(region=(0, 0, width, height)) -l0 = im.getpixel((posX[0], posY[0])) -l1 = im.getpixel((posX[0], posY[1])) -l2 = im.getpixel((posX[0], posY[2])) -r0 = im.getpixel((posX[1], posY[0])) -r1 = im.getpixel((posX[1], posY[1])) -r2 = im.getpixel((posX[1], posY[2])) +TREE = uint8([56, 116, 161]) -if l0[0] == 161 and l0[1] == 116 and l0[2] == 56: - q[0] = 'right' - pos = 'right' -else: - pos = 'left' -if l1[0] == 161 and l1[1] == 116 and l1[2] == 56: - q[1] = 'right' -if l2[0] == 161 and l2[1] == 116 and l2[2] == 56: - q[2] = 'right' +# from left to right +posY = [360, 460] +# from bottom to up +posX = [640, 540, 440, 340, 240, 140] -qlen = 3 -while True: - if qlen == 3: - now = q[0] - move(pos, now) - now = q[1] - move(pos, now) - now = q[2] - move(pos, now) - qlen = 0 - elif qlen == 0: - im = pg.screenshot(region=(0, 0, width, height)) - l0 = im.getpixel((posX[0], posY[0])) - l1 = im.getpixel((posX[0], posY[1])) - l2 = im.getpixel((posX[0], posY[2])) +def is_tree(c1): + if c1[0] == TREE[0] and c1[1] == TREE[1] and c1[2] == TREE[2]: + return True + else: + return False - r0 = im.getpixel((posX[1], posY[0])) - r1 = im.getpixel((posX[1], posY[1])) - r2 = im.getpixel((posX[1], posY[2])) - if l0[0] == 161 and l0[1] == 116 and l0[2] == 56: - q[0] = 'right' +def parse_screen(img, moves): + left = [img[x, posY[0]] for x in posX] + for i in range(6): + if is_tree(left[i]): + moves.append("right, right") else: - q[0] = 'left' - if l1[0] == 161 and l1[1] == 116 and l1[2] == 56: - q[1] = 'right' - else: - q[1] = 'left' - if l2[0] == 161 and l2[1] == 116 and l2[2] == 56: - q[2] = 'right' - else: - q[2] = 'left' + moves.append("left, left") + - now = q[0] - move(pos, now) - now = q[1] - move(pos, now) - now = q[2] - move(pos, now) +with mss.mss() as sct: + screen = sct.monitors[1] + screen["width"] = screen["width"] / 2.0 + begin() - sleep(0.095) + while True: + img = array(sct.grab(screen)) + moves = list() + parse_screen(img, moves) + for m in moves: + press_and_release(m) + time.sleep(0.145) diff --git a/requirements.txt b/requirements.txt index 54b4a43..4084e6d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,85 @@ +mss==3.1.1 numpy==1.13.3 opencv-python==3.4.0.12 +Pillow==5.0.0 +PyAutoGUI==0.9.36 +PyMsgBox==1.0.6 +pyobjc==4.1 +pyobjc-core==4.1 +pyobjc-framework-Accounts==4.1 +pyobjc-framework-AddressBook==4.1 +pyobjc-framework-AppleScriptKit==4.1 +pyobjc-framework-AppleScriptObjC==4.1 +pyobjc-framework-ApplicationServices==4.1 +pyobjc-framework-Automator==4.1 +pyobjc-framework-AVFoundation==4.1 +pyobjc-framework-AVKit==4.1 +pyobjc-framework-CalendarStore==4.1 +pyobjc-framework-CFNetwork==4.1 +pyobjc-framework-CloudKit==4.1 +pyobjc-framework-Cocoa==4.1 +pyobjc-framework-Collaboration==4.1 +pyobjc-framework-Contacts==4.1 +pyobjc-framework-ContactsUI==4.1 +pyobjc-framework-CoreBluetooth==4.1 +pyobjc-framework-CoreData==4.1 +pyobjc-framework-CoreLocation==4.1 +pyobjc-framework-CoreServices==4.1 +pyobjc-framework-CoreText==4.1 +pyobjc-framework-CoreWLAN==4.1 +pyobjc-framework-CryptoTokenKit==4.1 +pyobjc-framework-DictionaryServices==4.1 +pyobjc-framework-DiskArbitration==4.1 +pyobjc-framework-EventKit==4.1 +pyobjc-framework-ExceptionHandling==4.1 +pyobjc-framework-FinderSync==4.1 +pyobjc-framework-FSEvents==4.1 +pyobjc-framework-GameCenter==4.1 +pyobjc-framework-GameController==4.1 +pyobjc-framework-GameKit==4.1 +pyobjc-framework-GameplayKit==4.1 +pyobjc-framework-ImageCaptureCore==4.1 +pyobjc-framework-IMServicePlugIn==4.1 +pyobjc-framework-InputMethodKit==4.1 +pyobjc-framework-InstallerPlugins==4.1 +pyobjc-framework-InstantMessage==4.1 +pyobjc-framework-Intents==4.1 +pyobjc-framework-IOSurface==4.1 +pyobjc-framework-iTunesLibrary==4.1 +pyobjc-framework-LatentSemanticMapping==4.1 +pyobjc-framework-LaunchServices==4.1 +pyobjc-framework-libdispatch==4.1 +pyobjc-framework-LocalAuthentication==4.1 +pyobjc-framework-MapKit==4.1 +pyobjc-framework-MediaAccessibility==4.1 +pyobjc-framework-MediaLibrary==4.1 +pyobjc-framework-MediaPlayer==4.1 +pyobjc-framework-ModelIO==4.1 +pyobjc-framework-MultipeerConnectivity==4.1 +pyobjc-framework-NetFS==4.1 +pyobjc-framework-NetworkExtension==4.1 +pyobjc-framework-NotificationCenter==4.1 +pyobjc-framework-OpenDirectory==4.1 +pyobjc-framework-Photos==4.1 +pyobjc-framework-PhotosUI==4.1 +pyobjc-framework-PreferencePanes==4.1 +pyobjc-framework-PubSub==4.1 +pyobjc-framework-QTKit==4.1 +pyobjc-framework-Quartz==4.1 +pyobjc-framework-SafariServices==4.1 +pyobjc-framework-SceneKit==4.1 +pyobjc-framework-ScreenSaver==4.1 +pyobjc-framework-ScriptingBridge==4.1 +pyobjc-framework-SearchKit==4.1 +pyobjc-framework-Security==4.1 +pyobjc-framework-SecurityFoundation==4.1 +pyobjc-framework-SecurityInterface==4.1 +pyobjc-framework-ServiceManagement==4.1 +pyobjc-framework-Social==4.1 +pyobjc-framework-SpriteKit==4.1 +pyobjc-framework-StoreKit==4.1 +pyobjc-framework-SyncServices==4.1 +pyobjc-framework-SystemConfiguration==4.1 +pyobjc-framework-WebKit==4.1 +PyScreeze==0.1.13 +PyTweening==1.0.3 -- cgit v1.2.3 From de95d753e77da1f21230b2699a8a5089d2e9a041 Mon Sep 17 00:00:00 2001 From: clarkzjw Date: Tue, 2 Jan 2018 22:05:43 +0800 Subject: + fix --- bot.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/bot.py b/bot.py index f19694a..0716450 100644 --- a/bot.py +++ b/bot.py @@ -2,7 +2,7 @@ import time import mss import pyautogui as pg -from keyboard import press_and_release +from keyboard import send from numpy import array, uint8 @@ -25,15 +25,6 @@ def is_tree(c1): return False -def parse_screen(img, moves): - left = [img[x, posY[0]] for x in posX] - for i in range(6): - if is_tree(left[i]): - moves.append("right, right") - else: - moves.append("left, left") - - with mss.mss() as sct: screen = sct.monitors[1] screen["width"] = screen["width"] / 2.0 @@ -42,7 +33,10 @@ with mss.mss() as sct: while True: img = array(sct.grab(screen)) moves = list() - parse_screen(img, moves) - for m in moves: - press_and_release(m) + left = [img[x, posY[0]] for x in posX] + for i in range(6): + if is_tree(left[i]): + send("right, right", True, True) + else: + send("left, left", True, True) time.sleep(0.145) -- cgit v1.2.3 From 2932e93298c57c5286d32c142bd3159868c6b6a5 Mon Sep 17 00:00:00 2001 From: clarkzjw Date: Tue, 2 Jan 2018 22:12:25 +0800 Subject: + add deps --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 4084e6d..4de35ff 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +keyboard==0.11.0 mss==3.1.1 numpy==1.13.3 opencv-python==3.4.0.12 -- cgit v1.2.3 From ee072aa886d73934ef90e8cb4c7978c278e64c73 Mon Sep 17 00:00:00 2001 From: clarkzjw Date: Tue, 2 Jan 2018 22:21:59 +0800 Subject: + fix --- requirements.txt | 80 -------------------------------------------------------- 1 file changed, 80 deletions(-) diff --git a/requirements.txt b/requirements.txt index 4de35ff..f30d3d3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,86 +1,6 @@ keyboard==0.11.0 mss==3.1.1 numpy==1.13.3 -opencv-python==3.4.0.12 -Pillow==5.0.0 PyAutoGUI==0.9.36 -PyMsgBox==1.0.6 pyobjc==4.1 pyobjc-core==4.1 -pyobjc-framework-Accounts==4.1 -pyobjc-framework-AddressBook==4.1 -pyobjc-framework-AppleScriptKit==4.1 -pyobjc-framework-AppleScriptObjC==4.1 -pyobjc-framework-ApplicationServices==4.1 -pyobjc-framework-Automator==4.1 -pyobjc-framework-AVFoundation==4.1 -pyobjc-framework-AVKit==4.1 -pyobjc-framework-CalendarStore==4.1 -pyobjc-framework-CFNetwork==4.1 -pyobjc-framework-CloudKit==4.1 -pyobjc-framework-Cocoa==4.1 -pyobjc-framework-Collaboration==4.1 -pyobjc-framework-Contacts==4.1 -pyobjc-framework-ContactsUI==4.1 -pyobjc-framework-CoreBluetooth==4.1 -pyobjc-framework-CoreData==4.1 -pyobjc-framework-CoreLocation==4.1 -pyobjc-framework-CoreServices==4.1 -pyobjc-framework-CoreText==4.1 -pyobjc-framework-CoreWLAN==4.1 -pyobjc-framework-CryptoTokenKit==4.1 -pyobjc-framework-DictionaryServices==4.1 -pyobjc-framework-DiskArbitration==4.1 -pyobjc-framework-EventKit==4.1 -pyobjc-framework-ExceptionHandling==4.1 -pyobjc-framework-FinderSync==4.1 -pyobjc-framework-FSEvents==4.1 -pyobjc-framework-GameCenter==4.1 -pyobjc-framework-GameController==4.1 -pyobjc-framework-GameKit==4.1 -pyobjc-framework-GameplayKit==4.1 -pyobjc-framework-ImageCaptureCore==4.1 -pyobjc-framework-IMServicePlugIn==4.1 -pyobjc-framework-InputMethodKit==4.1 -pyobjc-framework-InstallerPlugins==4.1 -pyobjc-framework-InstantMessage==4.1 -pyobjc-framework-Intents==4.1 -pyobjc-framework-IOSurface==4.1 -pyobjc-framework-iTunesLibrary==4.1 -pyobjc-framework-LatentSemanticMapping==4.1 -pyobjc-framework-LaunchServices==4.1 -pyobjc-framework-libdispatch==4.1 -pyobjc-framework-LocalAuthentication==4.1 -pyobjc-framework-MapKit==4.1 -pyobjc-framework-MediaAccessibility==4.1 -pyobjc-framework-MediaLibrary==4.1 -pyobjc-framework-MediaPlayer==4.1 -pyobjc-framework-ModelIO==4.1 -pyobjc-framework-MultipeerConnectivity==4.1 -pyobjc-framework-NetFS==4.1 -pyobjc-framework-NetworkExtension==4.1 -pyobjc-framework-NotificationCenter==4.1 -pyobjc-framework-OpenDirectory==4.1 -pyobjc-framework-Photos==4.1 -pyobjc-framework-PhotosUI==4.1 -pyobjc-framework-PreferencePanes==4.1 -pyobjc-framework-PubSub==4.1 -pyobjc-framework-QTKit==4.1 -pyobjc-framework-Quartz==4.1 -pyobjc-framework-SafariServices==4.1 -pyobjc-framework-SceneKit==4.1 -pyobjc-framework-ScreenSaver==4.1 -pyobjc-framework-ScriptingBridge==4.1 -pyobjc-framework-SearchKit==4.1 -pyobjc-framework-Security==4.1 -pyobjc-framework-SecurityFoundation==4.1 -pyobjc-framework-SecurityInterface==4.1 -pyobjc-framework-ServiceManagement==4.1 -pyobjc-framework-Social==4.1 -pyobjc-framework-SpriteKit==4.1 -pyobjc-framework-StoreKit==4.1 -pyobjc-framework-SyncServices==4.1 -pyobjc-framework-SystemConfiguration==4.1 -pyobjc-framework-WebKit==4.1 -PyScreeze==0.1.13 -PyTweening==1.0.3 -- cgit v1.2.3 From 8570740ab6233dc96a7261ec723bc3d180a15a5a Mon Sep 17 00:00:00 2001 From: clarkzjw Date: Wed, 3 Jan 2018 00:32:37 +0800 Subject: + fix --- bot.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/bot.py b/bot.py index 0716450..c419bbc 100644 --- a/bot.py +++ b/bot.py @@ -2,9 +2,12 @@ import time import mss import pyautogui as pg -from keyboard import send from numpy import array, uint8 +#from keyboard import send + +from pynput.keyboard import Key, Controller +keyboard = Controller() def begin(): pg.click(440, 900, 2) @@ -36,7 +39,16 @@ with mss.mss() as sct: left = [img[x, posY[0]] for x in posX] for i in range(6): if is_tree(left[i]): - send("right, right", True, True) + keyboard.press(Key.right) + keyboard.release(Key.right) + time.sleep(0.014) + keyboard.press(Key.right) + keyboard.release(Key.right) else: - send("left, left", True, True) - time.sleep(0.145) + keyboard.press(Key.left) + keyboard.release(Key.left) + time.sleep(0.014) + keyboard.press(Key.left) + keyboard.release(Key.left) + time.sleep(0.17) + -- cgit v1.2.3