如何让我的代码在python中做我想要的?

时间:2014-08-24 22:49:42

标签: python

这是我的代码,我希望它按照我定义的值执行我告诉它的操作" grind()"。我定义了我想要使用的值,但我不确定如何告诉它这样做。基本上我想要我的程序: mousePos((625,15)),time.sleep(0.1),leftclick(),mousePos((630,85)),time.sleep(0.5),leftClick(),time.sleep(.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()

1 个答案:

答案 0 :(得分:0)

你的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
相关问题