[英]how do I get my code in python to do what I want?
這是我的代碼,我希望它執行我在定義的值“ grind()”中告訴它要做的事情。 我定義了要使用的值,但是我不確定如何告訴它執行該操作。 基本上我希望我的程序執行以下操作:mousePos((625,15)),time.sleep(0.1),leftclick(),mousePos((630,85)),time.sleep(0.5),leftClick(),time。當我運行它時睡眠(.1)。
import ImageGrab
import os
import time
import win32api, win32con
import ImageOps
from numpy import *
# Globals
# ------------------
x_pad = 1
y_pad = 65
def screenGrab():
b1 = (x_pad+1, y_pad+1, x_pad+1238, y_pad+704)
im = ImageGrab.grab()
##im.save(os.getcwd() + '\\Snap__' + str(int(time.time())) +'.png', 'PNG')
return im
def leftClick():
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
time.sleep(.1)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)
print "Click."
def leftDown():
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
time.sleep(.5)
print 'left Down'
def leftUp():
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)
time.sleep(.5)
print 'left release'
def mousePos(cord):
win32api.SetCursorPos((x_pad + cord[0], y_pad + cord[1]))
def get_cords():
x,y = win32api.GetCursorPos()
x = x - x_pad
y = y - y_pad
print x,y
class Cord:
f_spiritpt = (133, 292)
f_hp = (133, 210)
def grind():
s = screenGrab()
if ((s.getpixel(cord.f_spiritpt) == (165, 0, 0)) == (s.getpixel(cord.f_hp) == (0, 148, 21))):
mousePos((625, 15))
time.sleep(0.1)
leftclick()
mousePos((630, 85))
time.sleep(0.5)
leftClick()
time.sleep(.1)
else:
mousePos((255, 15))
time.sleep(60)
leftclick()
def main():
pass
if __name__ == '__main__':
main()
您需要在if語句中添加and
:
if s.getpixel(cord.f_spiritpt) == (165, 0, 0) and s.getpixel(cord.f_hp) == (0, 148, 21)
In [29]: foo = 4
In [30]: bar = 5
In [31]: if foo == 4 == bar == 5:
print foo
....:
In [32]: if foo == 4 and bar == 5:
print foo
....:
4
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.