Partage
  • Partager sur Facebook
  • Partager sur Twitter

Comment trouver la pos d'une image sur l'écran ?

Une icone par exemple.

    12 août 2018 à 17:35:51

    Je crée une IA qui fait les action d'un humain normal(sur l'ordi) et qui déplace la souris pour clicker sur les icones du bureau, je cherche a ce quel soit presque utilisable sur tout les ordi.Donc je cherche, a récupérer la position d'une icone pour déplacer la souris dessus, et clicker !

    Voici mon code(pour l'instant):

    import time
    from math import *
    import random
    import win32api
    want = []
    def setCursorPos(ax,ay):
        global win32api
        global x
        global y
        win32api.SetCursorPos((ax,ay))
        x = ax
        y = ay
    def getCursorPos():
        global win32api
        return win32api.GetCursorPos()
    x, y = getCursorPos()
    def click(x,y):
        global win32api
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)
    def write(txt):
        for i in txt:
    	time.sleep(0.05)
    	key = win32api.VkKeyScan(i)
    	win32api.keybd_event(key,0)
    def moveCursorTo(x,y):
        global win32api
        global time 
        ax, ay = win32api.GetCursorPos()
        while (ax, ay) != (x, y):
    	ax, ay = win32api.GetCursorPos()
    	time.sleep(0.01)
    	if ax > x:
    	    win32api.SetCursorPos((ax-10,ay))
    	elif ax < x:
    	    win32api.SetCursorPos((ax+10,ay))
    	if ay > y:
    	    win32api.SetCursorPos((ax,ay-1))
    	elif ay < y:
    	    win32api.SetCursorPos((ax,ay+1))
    def bound():
        r = {}
        file = open("learned.inftxt")
        text = file.read()
        file.close()
        text = text.split("\n")
        for i in text:
            i = i.split(":")
            r[i[0]] = i[0]
        return r
    exist = True
    def allerate(var):
        return var+random.randint(-10,10)
    def learn():
        pass
    learned = bound()
    choice = []
    for name,func in learned:
        choice.append(name)
    def rchoice():
        global choice
        return choice[random.randin(0,len(choice))]
    while exist:
        #and some code
        break



    • Partager sur Facebook
    • Partager sur Twitter
      12 août 2018 à 18:06:20

      PlutonionChana321123 a écrit:

      Je crée une IA qui fait les action d'un humain normal(sur l'ordi) et qui déplace la souris pour clicker sur les icones du bureau, je cherche a ce quel soit presque utilisable sur tout les ordi.Donc je cherche, a récupérer la position d'une icone pour déplacer la souris dessus, et clicker !

      Voici mon code(pour l'instant):

      import time
      from math import *
      import random
      import win32api
      want = []
      def setCursorPos(ax,ay):
          global win32api
          global x
          global y
          win32api.SetCursorPos((ax,ay))
          x = ax
          y = ay
      def getCursorPos():
          global win32api
          return win32api.GetCursorPos()
      x, y = getCursorPos()
      def click(x,y):
          global win32api
          win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
          win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)
      def write(txt):
          for i in txt:
      	time.sleep(0.05)
      	key = win32api.VkKeyScan(i)
      	win32api.keybd_event(key,0)
      def moveCursorTo(x,y):
          global win32api
          global time 
          ax, ay = win32api.GetCursorPos()
          while (ax, ay) != (x, y):
      	ax, ay = win32api.GetCursorPos()
      	time.sleep(0.01)
      	if ax > x:
      	    win32api.SetCursorPos((ax-10,ay))
      	elif ax < x:
      	    win32api.SetCursorPos((ax+10,ay))
      	if ay > y:
      	    win32api.SetCursorPos((ax,ay-1))
      	elif ay < y:
      	    win32api.SetCursorPos((ax,ay+1))
      def bound():
          r = {}
          file = open("learned.inftxt")
          text = file.read()
          file.close()
          text = text.split("\n")
          for i in text:
              i = i.split(":")
              r[i[0]] = i[0]
          return r
      exist = True
      def allerate(var):
          return var+random.randint(-10,10)
      def learn():
          pass
      learned = bound()
      choice = []
      for name,func in learned:
          choice.append(name)
      def rchoice():
          global choice
          return choice[random.randin(0,len(choice))]
      while exist:
          #and some code
          break



      en utilant win32api c'est déjà mal parti pour que ça marche sur Linux et MacOS ...

      • Partager sur Facebook
      • Partager sur Twitter
        17 août 2018 à 8:33:16

        Je sais, mais j'adapte après pour les os différents.
        • Partager sur Facebook
        • Partager sur Twitter

        Comment trouver la pos d'une image sur l'écran ?

        × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
        × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
        • Editeur
        • Markdown