Added comments.

This commit is contained in:
Sheldon 2021-02-19 19:00:15 +08:00
parent 12e4ac06e3
commit 446a9cecdc

View File

@ -1,44 +1,68 @@
from pyautogui import * from pyautogui import *
import time import time
#
# Functions.
#
def locateClick(imgname, alt=None, t=0.1, button="left"): def locateClick(imgname, alt=None, t=0.1, button="left"):
# Add pause to allow time for gui elements to appear.
time.sleep(t) time.sleep(t)
# Try to find image.
box = locateOnScreen(imgname) box = locateOnScreen(imgname)
print(imgname, "found at: ", box) print(imgname, "found at: ", box)
# It not found, try to find alt image.
if box is None: if box is None:
if alt is not None: if alt is not None:
locateClick(alt, button=button) locateClick(alt, button=button)
return False return False
# Get center of button and click.
x, y = box.left + box.width/2, box.top + box.height/2 x, y = box.left + box.width/2, box.top + box.height/2
moveTo(x, y) moveTo(x, y)
longClick(button=button) longClick(button=button)
return True return True
# Longer click, so FFXIV registers it
def longClick(t=0.100, button="left"): def longClick(t=0.100, button="left"):
mouseDown(button=button) mouseDown(button=button)
time.sleep(t) time.sleep(t)
mouseUp(button=button) mouseUp(button=button)
#
# Main logic.
#
count = 1; count = 1;
while(True): while(True):
# Option to pause every 5 iteratons to stop program
#if count%5 == 0: time.sleep(5); #if count%5 == 0: time.sleep(5);
# get center of screen # get center left third of of screen
start_x, start_y = size() start_x, start_y = size()
start_x /= 3; start_x /= 3;
start_y /= 2; start_y /= 2;
# move cursor to get focus, and click on sign
moveTo(start_x, start_y) moveTo(start_x, start_y)
click(); click();
longClick(button="right") longClick(button="right")
# will attempt to find gui buttons.
if not locateClick("PurchaseLand.png", t=0.3): if not locateClick("PurchaseLand.png", t=0.3):
press("esc"); press("esc");
continue continue
if not locateClick("FreeCompanyAlt.png", "FreeCompany.png"): pass if not locateClick("FreeCompanyAlt.png", "FreeCompany.png"):
if not locateClick("Yes.png"): pass press("esc");
press("esc");
continue
if not locateClick("Yes.png"):
press("esc");
press("esc");
press("esc");
continue
count += 1; count += 1;