Python Key Kullanımı

Sponsorlu Bağlantılar

FGHT

Üye
    Konu Sahibi
Python Key Kullanımı
Pythonla rek koduna göre tuşlara basacak sistem yapmaya çalıştım ama yazdığım kod çalışmadı. Kodun hatasının ne olduğunu da bulamadım. Çünkü kodu çalıştırınca hata da vermiyor. Bu konuda bilgisi olan yardım edebilir mi? Alttki kod çalışıyor ama çok verimsiz oldu. O kodu da daha kullanışlı hale nasıl getirebilirim? Kodu ekliyorum:
Kod:
[COLOR=#000000]import keypress[/COLOR]
[COLOR=#000000]from key_codes import *[/COLOR]
[COLOR=#000000]from graphics import *[/COLOR]
[COLOR=#000000]import time,appuifw,os[/COLOR]

[COLOR=#000000]time.sleep(5)[/COLOR]

[COLOR=#000000]def quit():[/COLOR]
[COLOR=#000000]   os.abort()[/COLOR]
[COLOR=#000000]appuifw.app.exit_key_=quit[/COLOR]

[COLOR=#000000]yol="E:\\Res\\ekran.Jpg"[/COLOR]

[COLOR=#000000]#yönler[/COLOR]
[COLOR=#000000]def right():print keypress.simulate_key(63496, 15)[/COLOR]
[COLOR=#000000]def left():print keypress.simulate_key(63495, 14)[/COLOR]
[COLOR=#000000]def up():print keypress.simulate_key(63497, 16)[/COLOR]
[COLOR=#000000]def down():print keypress.simulate_key(63498, 17)[/COLOR]
[COLOR=#000000]def bir():print keypress.simulate_key(49, 49)[/COLOR]
[COLOR=#000000]def iki():print keypress.simulate_key(50, 50)[/COLOR]
[COLOR=#000000]def yildiz():print keypress.simulate_key(EKeyStar, EScancodeStar)[/COLOR]
[COLOR=#000000]def kare():print keypress.simulate_key(35, 127)[/COLOR]

[COLOR=#000000]#renk[/COLOR]
[COLOR=#000000]def renk(path,x,y):[/COLOR]
[COLOR=#000000]    res=Image.open(path)[/COLOR]
[COLOR=#000000]    a=res.getpixel((x,y))[0][/COLOR]
[COLOR=#000000]    return a[/COLOR]
[COLOR=#000000]#resim çek[/COLOR]
[COLOR=#000000]def resimcek():[/COLOR]
[COLOR=#000000]    img = screenshot()[/COLOR]
[COLOR=#000000]    img.save(yol)[/COLOR]
[COLOR=#000000]#a=resim.getpixel(x,y)[/COLOR]
[COLOR=#000000]resimcek()[/COLOR]
[COLOR=#000000]def hareket(yon,x,y,rnk,x1,y1,rnk1):[/COLOR]
[COLOR=#000000]   while True:[/COLOR]
[COLOR=#000000]      resimcek()[/COLOR]
[COLOR=#000000]      if renk(yol,x,y)!=renk or renk(yol,x1,y1)!=rnk1:[/COLOR]
[COLOR=#000000]         if renk(yol,348,20)== (123,125,165):[/COLOR]
[COLOR=#000000]            resimcek()[/COLOR]
[COLOR=#000000]            time.sleep(1)[/COLOR]
[COLOR=#000000]         if renk(yol,28,386)== (99,16,8):[/COLOR]
[COLOR=#000000]            iki()[/COLOR]
[COLOR=#000000]            yildiz()[/COLOR]
[COLOR=#000000]            resimcek()[/COLOR]
[COLOR=#000000]         if renk(yol,328,386)== (8,97,24):[/COLOR]
[COLOR=#000000]            iki()[/COLOR]
[COLOR=#000000]            kare()[/COLOR]
[COLOR=#000000]            resimcek()[/COLOR]
[COLOR=#000000]         else:[/COLOR]
[COLOR=#000000]            yon[/COLOR]
[COLOR=#000000]            resimcek()[/COLOR]
[COLOR=#000000]      elif renk(yol,x,y)==renk or renk(yol,x1,y1)==rnk1:[/COLOR]
[COLOR=#000000]         break[/COLOR]
[COLOR=#000000]while True:[/COLOR]
[COLOR=#000000]   hareket(down(),67,50,(57,69,24),101,138,(222,215,189))[/COLOR]
[COLOR=#000000]   hareket(left(),237,61,(123,69,74),106,149,(156,97,57))[/COLOR]
[COLOR=#000000]   hareket(down(),93,47,(222,174,90),10,220,(57,146,99))[/COLOR]
[COLOR=#000000]   hareket(left(),313,47,(255,158,82),226,87,(74,158,115))[/COLOR]
[COLOR=#000000]   hareket(up(),270,131,(115,195,115),357,264,(57,182,41))[/COLOR]
[COLOR=#000000]   hareket(right(),270,90,(90,36,16),270,132,(0,81,0))[/COLOR]
[COLOR=#000000]   hareket(up(),227,294,(148,69,33),269,92,(255,166,57))[/COLOR]
[COLOR=#000000]   hareket(right(),282,237,(165,89,57),157,322,(24,85,57))[/COLOR]
[COLOR=#000000]   hareket(down(),304,288,(49,146,0),139,219,(82,170,132))[/COLOR]
[COLOR=#000000]   hareket(right(),269,91,(255,162,99),183,264,(99,166,99))[/COLOR]

Kod:
import keypressfrom key_codes import *
from graphics import *
import time,fgimage,appuifw,os


time.sleep(5)


def quit():
   os.abort()
appuifw.app.exit_key_=quit


yol="E:\\Res\\ekran.Jpg"


#yönler
def right():return keypress.simulate_key(63496, 15)
def left():return keypress.simulate_key(63495, 14)
def up():return keypress.simulate_key(63497, 16)
def down():return keypress.simulate_key(63498, 17)
def bir():return keypress.simulate_key(49, 49)
def iki():return keypress.simulate_key(50, 50)
def yildiz():return keypress.simulate_key(42, 42)
def kare():return keypress.simulate_key(35, 127)


#renk
def renk(path,x,y):
    res=Image.open(path)
    a=res.getpixel((x,y))[0]
    return a
#resim çek
def resimcek():
    img = screenshot()
    img.save(yol)


while True:
   while True:
      resimcek()
      if renk(yol,67,50)!=(57,69,24):
         if renk(yol,348,20)== (123,125,165):
            time.sleep(3)
         if renk(yol,30,385)== (148,12,16):
            iki()
            yildiz()
         if renk(yol,328,386)== (8,97,24):
            iki()
            kare()
         else:
            down()
      elif renk(yol,67,50)==(57,69,24):
         break
   while True:
      resimcek()
      if renk(yol,237,61)!=(123,69,74):
         if renk(yol,348,20)== (123,125,165):
            time.sleep(3)
         if renk(yol,30,385)== (148,12,16):
            iki()
            yildiz()
         if renk(yol,328,386)== (8,97,24):
            iki()
            kare()
         else:
            left()
      elif renk(yol,237,61)==(123,69,74):
         break
   while True:
      resimcek()
      if renk(yol,137,307)!=(189,255,189):
         if renk(yol,348,20)== (123,125,165):
            time.sleep(3)
         if renk(yol,30,385)== (148,12,16):
            iki()
            yildiz()
         if renk(yol,328,386)== (8,97,24):
            iki()
            kare()
         else:
            down()
      elif renk(yol,137,307)==(189,255,189):
         break
   while True:
      resimcek()
      if renk(yol,226,87)!=(74,158,115):
         if renk(yol,348,20)== (123,125,165):
            time.sleep(3)
         if renk(yol,30,385)== (148,12,16):
            iki()
            yildiz()
         if renk(yol,328,386)== (8,97,24):
            iki()
            kare()
         else:
            left()
      elif renk(yol,226,87)==(74,158,115):
         break
   while True:
      resimcek()
      if renk(yol,270,131)!=(115,195,115):
         if renk(yol,348,20)== (123,125,165):
            time.sleep(3)
         if renk(yol,30,385)== (148,12,16):
            iki()
            yildiz()
         if renk(yol,328,386)== (8,97,24):
            iki()
            kare()
         else:
            up()
      elif renk(yol,270,131)==(115,195,115):
         break
   while True:
      resimcek()
      if renk(yol,270,90)!=(90,36,16):
         if renk(yol,348,20)== (123,125,165):
            time.sleep(3)
         if renk(yol,30,385)== (148,12,16):
            iki()
            yildiz()
         if renk(yol,328,386)== (8,97,24):
            iki()
            kare()
         else:
            right()
      elif renk(yol,270,90)==(90,36,16):
         break
   while True:
      resimcek()
      if renk(yol,227,294)!=(148,69,33):
         if renk(yol,348,20)== (123,125,165):
            time.sleep(3)
         if renk(yol,30,385)== (148,12,16):
            iki()
            yildiz()
         if renk(yol,328,386)== (8,97,24):
            iki()
            kare()
         else:
            up()
      elif renk(yol,227,294)==(148,69,33):
         break
   while True:
      resimcek()
      if renk(yol,282,237)!=(165,89,57):
         if renk(yol,348,20)== (123,125,165):
            time.sleep(3)
         if renk(yol,30,385)== (148,12,16):
            iki()
            yildiz()
         if renk(yol,328,386)== (8,97,24):
            iki()
            kare()
         else:
            right()
      elif renk(yol,282,237)==(165,89,57):
         break
   while True:
      resimcek()
      if renk(yol,184,263)!=(24,89,33):
         if renk(yol,348,20)== (123,125,165):
            time.sleep(3)
         if renk(yol,30,385)== (148,12,16):
            iki()
            yildiz()
         if renk(yol,328,386)== (8,97,24):
            iki()
            kare()
         else:
            down()
      elif renk(yol,184,263)==(24,89,33):
         break
   while True:
      resimcek()
      if renk(yol,216,244)!=(74,113,0):
         if renk(yol,348,20)== (123,125,165):
            time.sleep(3)
         if renk(yol,30,385)== (148,12,16):
            iki()
            yildiz()
         if renk(yol,328,386)== (8,97,24):
            iki()
            kare()
         else:
            right()
      elif renk(yol,216,244)==(74,113,0):
         break

 

Benzer Konular



Üst Alt