简体   繁体   中英

Searching for images on screen is taking too long

I am new to python and I have found a project that interests me. It is a simple script that presses the keyboard keys when a button prompt is displayed on the screen. I took photos of the possible button prompts and I am scanning for them. the program works very well but is too slow.

For example let's say there is 12 button prompts, my program can only enter 10 before time runs out. I believe this is because of the 9 things it is scanning for. Is there any other way to accomplish what I am doing but faster, or is there another library I could try?

#method that actually looks for photos on screen
def look(self):
    self.z = imagesearch("press_z2.jpg")
    self.c = imagesearch("press_c2.jpg")
    self.s = imagesearch("press_s2.jpg")
    self.x = imagesearch("press_x2.jpg")
    self.w = imagesearch("press_w2.jpg")
    self.q = imagesearch("press_q2.jpg")
    self.e = imagesearch("press_e2.jpg")
    self.d = imagesearch("press_d2.jpg")
    self.a = imagesearch("press_a2.jpg")

def run(self):
    while True:
        self.look()

My code was posting weird so here is a link to the full thing: https://pastebin.com/5pWDfwXy

线程不是python中的实际线程,而是使用多处理

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