Da ich recht unerfahren in diesem Gebiet von Python bin, habe ich leider keine Ahnung mehr wie es weiter geht. Mein Code macht ein Screenshot von einem Teil des Bildes und legt filtert Helligkeiten heraus. Nun möchte ich, dass sich der Mauszeiger auf (am besten die größte), grüne Fläche bewegt, die auf dem Bild erkennbar ist. Dafür verwende ich die win32api. Vielen Dank im Voraus!
Hier die Problemstelle, bzw zum einbauen:
Code: Alles auswählen
import win32api, win32con
import time
from PIL import Image, ImageGrab
import os
import time
from PIL import ImageOps
from numpy import *
#Gobal Cords
x_pad = 0
y_pad = 0
c_Mitte = 960, 540
def screenGrab():
box = ()
im = ImageGrab.grab()
return im
def grab():
box = (0,0,1535,993)
screenGrab()
im = ImageOps.colorize(ImageOps.grayscale(ImageGrab.grab(box)), black="black", white="black", mid="green", blackpoint=105, whitepoint=130, midpoint=125)
im.save("C:/Users/m/BotPython/Bilder" + '\\full_snap__' + str(int(time.time())) + '.png', 'PNG')
Code: Alles auswählen
import win32api, win32con
import time
from PIL import Image, ImageGrab
import os
import time
from PIL import ImageOps
from numpy import *
#Gobal Cords
x_pad = 0
y_pad = 0
c_Mitte = 960, 540
def screenGrab():
box = ()
im = ImageGrab.grab()
#im.save("C:/Users/hahnm/BotPython/Bilder" + '\\full_snap__' + str(int(time.time())) + '.png', 'PNG')
return im
def grab():
box = (0,0,1535,993)
screenGrab()
im = ImageOps.colorize(ImageOps.grayscale(ImageGrab.grab(box)), black="black", white="black", mid="green", blackpoint=105, whitepoint=130, midpoint=125)
im.save("C:/Users/hahnm/BotPython/Bilder" + '\\full_snap__' + str(int(time.time())) + '.png', 'PNG')
# ----------------
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(.1)
print("left Down")
def leftUp():
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)
time.sleep(.1)
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)
def StartGame():
win32api.SetCursorPos((963, 645))
leftClick()
time.sleep(12)
win32api.SetCursorPos((593, 907))
leftClick()
time.sleep(.1)
win32api.SetCursorPos((965, 907))
leftClick()
time.sleep(.1)
win32api.SetCursorPos((1359, 907))
leftClick()
time.sleep(.1)
#def StartOver():
#time.sleep(5)
#StartOver()
#for i in range(6):
# print(get_cords())
# time.sleep(5)
#grab()
StartGame()
def main():
pass
if __name__ == '__main__':
main()