import win32,time
import win32api,win32gui,win32con
from ctypes import *
stop=0
from PIL import Image
def dig(x,y): ######挖方块函数,数据自行调整
win32api.SetCursorPos((x, y))
win32api.keybd_event(50, 0, 0, 0)
time.sleep(0.1)
win32api.keybd_event(50, 0, win32con.KEYEVENTF_KEYUP, 0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
time.sleep(0.5)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
def put(): #######垫方块函数,数据自行调整
win32api.SetCursorPos((1025, 672))
win32api.keybd_event(49, 0, 0, 0)
time.sleep(0.2)
win32api.keybd_event(49, 0, win32con.KEYEVENTF_KEYUP, 0)
win32api.keybd_event(32, 0, 0, 0)
time.sleep(0.2)
win32api.keybd_event(32, 0, win32con.KEYEVENTF_KEYUP, 0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
time.sleep(0.1)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
"""
下面是一个调试部分,一般不会用到
"""
time.sleep(4)
get = win32api.GetCursorPos()
print(get)
time.sleep(4)
"""
以下是主循环部分
"""
while -1:
chance=0
get=win32api.GetCursorPos()
gdi32 = windll.gdi32
user32 = windll.user32
hdc = user32.GetDC(None)
c = gdi32.GetPixel(hdc,1041,637) ##获取指定像素的颜色,用来判断人物是否移动
win32api.keybd_event(68, 0, 0, 0)
time.sleep(0.5)
win32api.keybd_event(68, 0, win32con.KEYEVENTF_KEYUP, 0)
#win32api.SetCursorPos((1000, 300))
gdi32 = windll.gdi32
user32 = windll.user32
hdc = user32.GetDC(None)
c1 = gdi32.GetPixel(hdc,1041,637) ##获取指定像素的颜色,用来判断人物是否移动
hex(c),hex(c1) ##十六进制化数据
if c1==c: ##判断像素颜色是否相同
stop+= 1
print(stop)
if 2<stop<4: ##搭方块函数
put()
elif stop==4: ##搭方块、垫方块部分
while chance<2:
dig(1007, 597)
dig(1026, 597)
put()
chance += 2
stop = 0
win32api.keybd_event(32, 0, 0, 0)
time.sleep(0.2)
win32api.keybd_event(32, 0, win32con.KEYEVENTF_KEYUP, 0)