Created
June 16, 2020 18:57
-
-
Save rxw1/b36ebc5a9c3615662bca7bd9db8b01d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/home/asdf/.pyenv/shims/python | |
import time | |
import pynput | |
import itertools | |
import argparse | |
import subprocess | |
from pynput.mouse import Button | |
from pynput.keyboard import Key | |
ENCODING = 'utf-8' | |
################################################################# | |
def getopt(opt=None): | |
parser = argparse.ArgumentParser(description="PoE Helper") | |
parser.add_argument("-s", action="store_true", default=False, dest="stash", help="put stuff to stash") | |
parser.add_argument("-i", action="store_true", default=False, dest="inventory", help="put stuff to inventory") | |
parser.add_argument("-c", action="store_true", default=False, | |
dest="clipboard", help="get item info from clipboard") | |
parser.add_argument("args", nargs=argparse.REMAINDER) | |
args = parser.parse_args() | |
if opt: | |
if opt not in args: | |
raise ValueError("Opt {} not found in args {}.".format(opt, args)) | |
return vars(args)[opt] | |
return parser.parse_args() | |
################################################################# | |
mouse = pynput.mouse.Controller() | |
keyboard = pynput.keyboard.Controller() | |
SQUARE_SIZE = 66 + 4 | |
START_X = 25 + (SQUARE_SIZE / 2) | |
START_Y = 219 + (SQUARE_SIZE / 2) | |
INV_START_X = 1730 | |
INV_START_Y = 820 | |
INV_END_X = 2570 | |
INV_END_Y = 1170 | |
mouse.position = (START_X, START_Y) | |
################################################################# | |
#a = (57, 251) | |
# | |
#cx = 57 | |
#cy = 251 | |
def ctrl_click(): | |
keyboard.press(Key.ctrl) | |
mouse.press(Button.left) | |
#time.sleep(.1) | |
mouse.release(Button.left) | |
keyboard.release(Key.ctrl) | |
def stash_to_inv (): | |
for x in range(57, 860, 70): | |
for y in range(251, 1024, 70): | |
print(x, y) | |
mouse.position = (x, y) | |
ctrl_click() | |
time.sleep(0.1) | |
def inv_to_stash (): | |
for x in range(INV_START_X, INV_END_X, SQUARE_SIZE): | |
for y in range(INV_START_Y, INV_END_Y, SQUARE_SIZE): | |
print(x, y) | |
mouse.position = (x, y) | |
ctrl_click() | |
time.sleep(0.05) | |
def get_clipboard(): | |
f = open("/home/asdf/poeinv.txt","w+") | |
with keyboard.pressed(Key.ctrl): | |
keyboard.press('c') | |
time.sleep(.2) | |
keyboard.release('c') | |
#time.sleep(.5) | |
#keyboard.release(Key.ctrl) | |
#keyboard.release(Key.c) | |
p = subprocess.Popen(['xsel', "-b", '-o'], | |
stdout=subprocess.PIPE, close_fds=True) | |
stdout, stderr = p.communicate() | |
d = stdout.decode(ENCODING) | |
print(d) | |
f.write(d) | |
f.close() | |
return stdout.decode(ENCODING) | |
#stash_to_inv() | |
if getopt("stash"): | |
print("inv to stash") | |
inv_to_stash() | |
elif getopt("inventory"): | |
print("inv to stash") | |
stash_to_inv() | |
elif getopt("clipboard"): | |
INV_START_X = 1730 | |
INV_START_Y = 820 | |
INV_END_X = 2570 | |
INV_END_Y = 1170 | |
STEP = 66 + 4 | |
DELAY = 0.1 | |
inventory = [] | |
ix = 0 | |
iy = 0 | |
pitem = None | |
# clear clipboard | |
subprocess.Popen(['xsel', "-b", '-c'], | |
stdout=subprocess.PIPE, close_fds=True) | |
for x in range(INV_START_X, INV_END_X, STEP): | |
ix += 1 | |
for y in range(INV_START_Y, INV_END_Y, STEP): | |
iy += 1 | |
mouse.position = (x, y) | |
# clear clipboard | |
subprocess.Popen(['xsel', "-b", '-c'], | |
stdout=subprocess.PIPE, close_fds=True) | |
with keyboard.pressed(Key.ctrl): | |
keyboard.press('c') | |
#time.sleep(DELAY) | |
keyboard.release('c') | |
time.sleep(DELAY) | |
# get clipboard | |
p = subprocess.Popen(['xsel', "-b", '-o'], | |
stdout=subprocess.PIPE, close_fds=True) | |
stdout, stderr = p.communicate() | |
item = stdout.decode(ENCODING) | |
if (item): | |
iteml = item.split("\n") | |
print("item: %s" % iteml[1]) | |
#if (citem != pitem): | |
# inventory.append(citem) | |
# pitem = citem | |
#for item in inventory: | |
# print(item.split("\n")[1]) | |
#f.write(d) | |
#f.write(ix, iy) | |
#print(len(inventory)) | |
#f = open("/home/asdf/poe.log","w+") | |
#f.write(a) | |
#f.close() | |
#def iterate_inventory(): | |
# | |
# for x in range(57, 860, 70): | |
# for y in range(251, 1024, 70): | |
# | |
# | |
# | |
# | |
#for y in itertools.repeat(None, 11): | |
# cx = 57 | |
# for x in itertools.repeat(None, 11): | |
# mouse.position = (cx, cy) | |
# time.sleep(.1) | |
# print(cx, cy) | |
# cy += 70 | |
# cx += 70 | |
#for x in itertools.repeat(None, 11): | |
# cx += 66 + 4 | |
# for y in itertools.repeat(None, 2): | |
# ctrl_click() | |
# cy += 66 + 4 | |
# mouse.position = (x, y) | |
# | |
#print('The current pointer position is {0}'.format( | |
# mouse.position)) | |
# | |
#keyboard.press(Key.ctrl) | |
# | |
#mouse.press(Button.left) | |
#mouse.release(Button.left) | |
# | |
#keyboard.release(Key.ctrl) | |
#time.sleep(.2) | |
#mouse.position = (10, 20) | |
#print('Now we have moved it to {0}'.format( | |
# mouse.position)) | |
# Move pointer relative to current position | |
#mouse.move(-65, 0) | |
# | |
#time.sleep(.2) | |
# | |
#mouse.press(Button.left) | |
#mouse.release(Button.left) | |
# Press and release | |
#mouse.press(Button.left) | |
# Double click; this is different from pressing and releasing | |
# twice on macOS | |
#mouse.click(Button.left, 2) | |
# Scroll two steps down | |
#mouse.scroll(0, 2) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment