Advertisement
Eliont

Simple Path of Exile loot auto sort script

Jun 23rd, 2019
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.41 KB | None | 0 0
  1. import win32clipboard
  2.  
  3. from time import sleep
  4.  
  5. from pywinauto.application import Application
  6. from pywinauto.keyboard import send_keys
  7. from pywinauto.mouse import move
  8. from pywinauto.findwindows import WindowNotFoundError
  9. from pywinauto.findwindows import ElementNotFoundError
  10.  
  11. from win32api import GetKeyState
  12. from win32con import VK_NUMLOCK  
  13.  
  14. from pywinauto.timings import Timings
  15. from pywinauto.timings import TimeoutError
  16.  
  17. from ctypes import windll
  18.  
  19. Timings.fast()
  20.  
  21. ###
  22.  
  23. def item_data():
  24.     try:
  25.         win32clipboard.OpenClipboard()
  26.         data = win32clipboard.GetClipboardData()
  27.         win32clipboard.CloseClipboard()
  28.     except TypeError:
  29.         return dict()
  30.        
  31.     # print (data)
  32.    
  33.     if windll.user32.OpenClipboard(None):
  34.         windll.user32.EmptyClipboard()
  35.         windll.user32.CloseClipboard()
  36.    
  37.     properties = {}
  38.     itemdata = data.split('\n')
  39.     if len(itemdata) > 1:
  40.         properties['name'] = itemdata[1]
  41.         for line in itemdata:
  42.             key_value = line.split(': ')
  43.             if len(key_value) == 2:
  44.                 key,value = key_value
  45.                 properties[key] = value
  46.    
  47.     return properties
  48.    
  49. def get_key(dic,key):
  50.     if key in dic:
  51.         return dic[key]
  52.     else:
  53.         return ''
  54.        
  55. def select_tab(key):
  56.     global last_selected_tab
  57.     if last_selected_tab != key:
  58.         app.window(title=appname).click_input(button='left', coords=(tab[key], tab_y))
  59.         sleep(0.1)
  60.         app.window(title=appname).click_input(button='left', coords=(tab[key], tab_y))
  61.         sleep(0.1)
  62.         last_selected_tab = key
  63.  
  64. ###
  65.  
  66. last_selected_tab = ''
  67.  
  68. cell_size = 50
  69. grid = 10,5
  70. # grid = 9,5
  71. # grid = 1,1
  72. base = 1335, 598
  73.  
  74. tab_y = 159
  75. tab = {}
  76. tab['orb'] = 60 * 1
  77. tab['ess'] = 60 * 2
  78. tab['frg'] = 60 * 3
  79. tab['map'] = 60 * 4
  80. tab['div'] = 60 * 5
  81. tab['gcp'] = 60 * 6
  82. tab['chm'] = 60 * 7
  83. tab['unq'] = 60 * 8
  84. tab['tmp'] = 60 * 9
  85.  
  86. rgb = ["R-G-B","R-B-G","B-R-G","B-G-R","G-R-B","G-B-R"]
  87.  
  88. appname = "Path of Exile"
  89. app = Application().connect(title=appname)
  90. print (appname)
  91.  
  92. ###
  93.  
  94. while(True):
  95.     if GetKeyState(VK_NUMLOCK):
  96.         for x in range(0,grid[0]):
  97.             if not GetKeyState(VK_NUMLOCK): break
  98.             for y in range(0,grid[1]):
  99.                 if not GetKeyState(VK_NUMLOCK): break
  100.                 try:
  101.                     move(coords=(base[0]+cell_size*x, base[1]+cell_size*y))
  102.                     send_keys('^c')
  103.                     sleep(0.5)
  104.                    
  105.                     data = item_data()
  106.                    
  107.                     if get_key(data,'Rarity').startswith('Currency') and 'Essence of' in get_key(data,'name'):
  108.                         select_tab('ess')
  109.                    
  110.                     elif get_key(data,'Rarity').startswith('Currency'):
  111.                         select_tab('orb')
  112.                        
  113.                     elif get_key(data,'Rarity').startswith('Divination Card'):
  114.                         select_tab('div')
  115.                        
  116.                     elif len(get_key(data,'Map Tier')):
  117.                         select_tab('map')
  118.                        
  119.                     elif get_key(data,'Rarity').startswith('Unique'):
  120.                         select_tab('unq')
  121.                        
  122.                     elif any(substring in get_key(data,'Sockets') for substring in rgb):
  123.                         select_tab('chm')
  124.                        
  125.                     elif get_key(data,'Rarity').startswith('Gem') and len(get_key(data,'Quality')):
  126.                         select_tab('gcp')
  127.                        
  128.                     elif len(data):
  129.                         select_tab('tmp')
  130.                        
  131.                     else:
  132.                         continue
  133.                        
  134.                     sleep(0.5)                        
  135.                     app.window(title=appname).click_input(button='left', coords=(base[0]+cell_size*x, base[1]+cell_size*y),pressed='control')
  136.                     sleep(0.3)                        
  137.                     app.window(title=appname).click_input(button='left', coords=(base[0]+cell_size*x, base[1]+cell_size*y),pressed='control')
  138.                     sleep(0.3)
  139.                        
  140.                 except (WindowNotFoundError, ElementNotFoundError, TimeoutError):
  141.                     break
  142.                    
  143.     sleep(0.1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement