简体   繁体   中英

how do I get my code in python to do what I want?

This is my code and I want it to do what I told it to do in my defined value "grind()". I defined the values that I wanted to use but I'm not sure how to tell it to do it. Basically I want my program to do: mousePos((625, 15)), time.sleep(0.1), leftclick(), mousePos((630, 85)), time.sleep(0.5), leftClick(), time.sleep(.1) when I run it.

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()

You need an and in your if statement:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM