feat: saved previously found click pos, use material ui
This commit is contained in:
parent
fc79000a48
commit
dbc695a9c7
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"python.formatting.provider": "black"
|
||||||
|
}
|
91
autoclick.py
91
autoclick.py
@ -5,6 +5,13 @@ import time
|
|||||||
# Functions.
|
# Functions.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
def do_click(box, button):
|
||||||
|
time.sleep(0.2)
|
||||||
|
x, y = box.left + box.width / 2, box.top + box.height / 2
|
||||||
|
moveTo(x, y)
|
||||||
|
long_click(button=button)
|
||||||
|
|
||||||
|
|
||||||
# Locates gui element.
|
# Locates gui element.
|
||||||
def locate_click(imgname, alt=None, t=0.1, button="left"):
|
def locate_click(imgname, alt=None, t=0.1, button="left"):
|
||||||
# Add pause to allow time for gui elements to appear.
|
# Add pause to allow time for gui elements to appear.
|
||||||
@ -17,14 +24,13 @@ def locate_click(imgname, alt=None, t=0.1, button="left"):
|
|||||||
# It not found, try to find alt image.
|
# 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:
|
||||||
locate_click(alt, button=button)
|
box = locate_click(alt, button=button)
|
||||||
return False
|
return False, None
|
||||||
|
|
||||||
# Get center of button and click.
|
# Get center of button and click.
|
||||||
x, y = box.left + box.width/2, box.top + box.height/2
|
do_click(box, button)
|
||||||
moveTo(x, y)
|
return True, box
|
||||||
long_click(button=button)
|
|
||||||
return True
|
|
||||||
|
|
||||||
# Longer click, so FFXIV registers it.
|
# Longer click, so FFXIV registers it.
|
||||||
def long_click(t=0.100, button="left"):
|
def long_click(t=0.100, button="left"):
|
||||||
@ -32,49 +38,62 @@ def long_click(t=0.100, button="left"):
|
|||||||
time.sleep(t)
|
time.sleep(t)
|
||||||
mouseUp(button=button)
|
mouseUp(button=button)
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Main logic.
|
# Main logic.
|
||||||
#
|
#
|
||||||
|
|
||||||
# Define image paths:
|
# Define image paths:
|
||||||
img_dir = "img/"
|
img_dir = "img/"
|
||||||
|
img_purchaseland = img_dir + "PurchaseLand.png"
|
||||||
|
img_purchaseland_alt = None
|
||||||
|
img_freecompany = img_dir + "FreeCompany.png"
|
||||||
|
img_freecompany_alt = img_dir + "FreeCompanyAlt.png"
|
||||||
|
img_yes = img_dir + "Yes.png"
|
||||||
|
img_yes_alt = None
|
||||||
|
count = 1
|
||||||
|
|
||||||
img_purchaseland = img_dir+"PurchaseLand.png"
|
# save pos
|
||||||
img_purchaseland_alt = None;
|
saved_purchase = None
|
||||||
|
saved_yes = None
|
||||||
|
|
||||||
img_freecompany = img_dir+"FreeCompany.png"
|
while True:
|
||||||
img_freecompany_alt = img_dir+"FreeCompanyAlt.png"
|
|
||||||
|
|
||||||
img_yes = img_dir+"Yes.png"
|
|
||||||
img_yes_alt = None;
|
|
||||||
|
|
||||||
count = 1;
|
|
||||||
while(True):
|
|
||||||
# Option to pause every 5 iteratons to stop program
|
# 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 left third of 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
|
# move cursor to get focus, and click on sign
|
||||||
moveTo(start_x, start_y)
|
moveTo(start_x, start_y)
|
||||||
click();
|
click()
|
||||||
long_click(button="right")
|
long_click(button="right")
|
||||||
|
|
||||||
# Attempt to find gui buttons.
|
# Attempt to find gui buttons.
|
||||||
if not locate_click(img_purchaseland, img_purchaseland_alt, t=0.35):
|
if saved_purchase is not None:
|
||||||
press("esc");
|
print("using saved purchase pos\n\t", saved_purchase)
|
||||||
continue
|
do_click(saved_purchase, "left")
|
||||||
if not locate_click(img_freecompany_alt, img_freecompany):
|
else:
|
||||||
press("esc");
|
success, box = locate_click(img_purchaseland, img_purchaseland_alt, t=0.4)
|
||||||
press("esc");
|
if not success:
|
||||||
continue
|
press("esc")
|
||||||
if not locate_click(img_yes, img_yes_alt):
|
continue
|
||||||
press("esc");
|
saved_purchase = box
|
||||||
press("esc");
|
# if not locate_click(img_freecompany_alt, img_freecompany):
|
||||||
continue
|
# press("esc");
|
||||||
|
# press("esc");
|
||||||
count += 1;
|
# continue
|
||||||
|
if saved_yes is not None:
|
||||||
|
print("using saved yes pos\n\t", saved_yes)
|
||||||
|
do_click(saved_yes, "left")
|
||||||
|
else:
|
||||||
|
sucess, box = locate_click(img_yes, img_yes_alt)
|
||||||
|
if not success:
|
||||||
|
press("esc")
|
||||||
|
press("esc")
|
||||||
|
continue
|
||||||
|
saved_yes = box
|
||||||
|
|
||||||
|
count += 1
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 1.7 KiB |
BIN
img/Yes.png
BIN
img/Yes.png
Binary file not shown.
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 1.0 KiB |
Loading…
Reference in New Issue
Block a user