from PIL import ImageGrab
import keyboard
import threading
threads = []
play_num = input('are you playing as player (1) or (2)> ')
def get_img(player_num):
image = ImageGrab.grab()
if player_num == '1':
b1 = image.getpixel((246, 144))
b2 = image.getpixel((426, 151))
b3 = image.getpixel((591, 136))
b4 = image.getpixel((761, 151))
return b1 and b2 and b3 and b4
elif player_num == '2':
b1 = image.getpixel((1161, 151))
b2 = image.getpixel((1325, 164))
b3 = image.getpixel((1489, 128))
b4 = image.getpixel((1671, 149))
return b1 and b2 and b3 and b4
else:
quit()
def arrow_one(color_index):
if not color_index[0] == 255:
pass
else:
keyboard.press('a')
keyboard.release('a')
def arrow_two(color_index):
if not color_index[0] == 255:
pass
else:
keyboard.press('s')
keyboard.release('s')
def arrow_tree(color_index):
if not color_index[0] == 255:
pass
else:
keyboard.press('d')
keyboard.release('d')
def arrow_four(color_index):
if not color_index[0] == 255:
pass
else:
keyboard.press('f')
keyboard.release('f')
def stop_code():
if keyboard.is_pressed('a' and 'c'):
print('gg')
quit()
if __name__ == '__main__':
while True:
if keyboard.is_pressed('space'):
while True:
color1, color2, color3, color4 = get_img(play_num)
for _ in range(1):
stop_check = threading.Thread(target=stop_code())
step1 = threading.Thread(target=arrow_one(color1))
step2 = threading.Thread(target=arrow_two(color2))
step3 = threading.Thread(target=arrow_tree(color3))
step4 = threading.Thread(target=arrow_four(color4))
step1.start()
step2.start()
step3.start()
step4.start()
stop_check.start()
threads.append(step1 and step2 and step3 and step4 and stop_check)
for thread in threads:
thread.join()
else:
pass
Each funtion goes through to check if its pixel is white or not, and if its not white, it presses the button accordingly
the get_img fucntion is what gets all the colors and returns b1, b2, ect..., It shows that its expecting 4 (becuase i have 4 things connected to it), however I get the error:
ValueError: not enough values to unpack (expected 4, got 3)
but I clearly have 4 values being returned and im completly stumped, i would appreciate any help given.