from time import sleep # from subprocess import check_output import re import keyring # import subprocess as sp import keyboard as kb import pyautogui as gui import pywinctl as gw from pywinau import automate_write sleep_ = 0.025 CONF = 0.8 mentor_user = 'Utilizator: Master' def abbr(short_cut, abbr_message, modifier=''): shc = short_cut if shc == ' ': shc1 = re.findall(' +', shc) gui.typewrite(abbr_message) gui.press('left', presses=1, interval=0.001) gui.press('backspace', presses=1, interval=0.001) gui.press('right', presses=1, interval=0.001) else: shc1 = re.findall('[a-z0-9-]*', shc) gui.press('backspace', presses=len(''.join(shc1) + modifier), interval=sleep_) kb.write(abbr_message) def mv_mouse_right(): size = gui.size() gui.moveTo(size[0] / 1.01, size[1] / 1.01) # gui.click() def mv_mouse_cent(): size = gui.size() gui.moveTo(size[0] / 2, size[1] / 2) def _printer(func): def wrapper(): print(func.__doc__, 'h_key performed') return func() return wrapper def nord(): gui.press('backspace', 2) gui.typewrite('NN1984ord') def h_key(): '''mentor list config''' gui.keyDown('shift') gui.press('tab', presses=9, interval=sleep_) gui.keyUp('shift') sleep(0.5) gui.press('right', presses=1) @_printer def remake_journal(): '''refacere jurnal''' try: # mentor_win = gw.getWindowsWithTitle(mentor_user)[0] active_win = gw.getActiveWindowTitle() if mentor_user.title() in active_win.title(): # mentor_win.activate() butt_x_y = gui.locateCenterOnScreen(f'mentor_imgs/contabile.png', confidence=CONF) sleep(0.1) if butt_x_y: gui.click(butt_x_y[0], butt_x_y[1]) pos_x_y = gui.position() gui.moveTo(pos_x_y[0], pos_x_y[1]) gui.press('enter') mv_mouse_cent() # gui.move(1, 1) except IndexError: print('start mentor') @_printer def cash_registry(): '''registru de casa''' try: # mentor_win = gw.getWindowsWithTitle(mentor_user)[0] active_win = gw.getActiveWindowTitle() if mentor_user.title() in active_win.title(): # mentor_win.activate() butt_x_y = gui.locateCenterOnScreen(f'mentor_imgs/trezorerie.png', confidence=CONF) sleep(0.1) if butt_x_y: gui.click(butt_x_y[0], butt_x_y[1]) pos_x_y = gui.position() gui.moveTo(pos_x_y[0], pos_x_y[1]) gui.press('right', 1, sleep_) gui.press('down', 1, sleep_) gui.press('return', 1, sleep_) mv_mouse_cent() # print('please activate Window LISTE') except IndexError: print('start mentor') @_printer def clients_ron(): '''clienti datornici''' try: # mentor_win = gw.getWindowsWithTitle(mentor_user)[0] active_win = gw.getActiveWindowTitle() if mentor_user.title() in active_win.title(): # mentor_win.activate() butt_x_y = gui.locateCenterOnScreen(f'mentor_imgs/parteneri.png', confidence=CONF) sleep(0.1) if butt_x_y: gui.click(butt_x_y[0], butt_x_y[1]) pos_x_y = gui.position() gui.moveTo(pos_x_y[0], pos_x_y[1]) gui.press('right', 1, sleep_) gui.press('down', 11, 0.0) gui.press('return', 2, sleep_) mv_mouse_cent() except IndexError: print('start mentor') @_printer def verif_balance(): '''balanta de verificare''' try: # mentor_win = gw.getWindowsWithTitle(mentor_user)[0] active_win = gw.getActiveWindowTitle() if mentor_user.title() in active_win.title(): # mentor_win.activate() butt_x_y = gui.locateCenterOnScreen(f'mentor_imgs/contabile.png', confidence=CONF) sleep(0.1) if butt_x_y: gui.click(butt_x_y[0], butt_x_y[1]) pos_x_y = gui.position() gui.moveTo(pos_x_y[0], pos_x_y[1]) gui.press('down', 1, sleep_) gui.press('right', 1, sleep_) gui.press('down', 1, sleep_) gui.press('return', 2, sleep_) mv_mouse_cent() except IndexError: print('start mentor') @_printer def suppliers_ron(): '''furnizori neachitati''' try: # mentor_win = gw.getWindowsWithTitle(mentor_user)[0] active_win = gw.getActiveWindowTitle() if mentor_user.title() in active_win.title(): # mentor_win.activate() butt_x_y = gui.locateCenterOnScreen(f'mentor_imgs/parteneri.png', confidence=CONF) sleep(0.1) if butt_x_y: gui.click(butt_x_y[0], butt_x_y[1]) pos_x_y = gui.position() gui.moveTo(pos_x_y[0], pos_x_y[1]) gui.press('down', 1, sleep_) gui.press('right', 1, sleep_) gui.press('down', 9, 0.0) gui.press('return', 2, sleep_) mv_mouse_cent() except IndexError: print('start mentor') @_printer def suppliers_val(): '''furnizori neachitati eur''' try: # mentor_win = gw.getWindowsWithTitle(mentor_user)[0] active_win = gw.getActiveWindowTitle() if mentor_user.title() in active_win.title(): # mentor_win.activate() butt_x_y = gui.locateCenterOnScreen(f'mentor_imgs/parteneri.png', confidence=CONF) sleep(0.1) if butt_x_y: gui.click(butt_x_y[0], butt_x_y[1]) pos_x_y = gui.position() gui.moveTo(pos_x_y[0], pos_x_y[1]) gui.press('down', 1, sleep_) gui.press('right', 1, sleep_) gui.press('down', 10, 0.0) gui.press('return', 2, sleep_) mv_mouse_cent() except IndexError: print('start mentor') @_printer def bank_registry_ron(): '''registru de banca lei''' try: # mentor_win = gw.getWindowsWithTitle(mentor_user)[0] active_win = gw.getActiveWindowTitle() if mentor_user.title() in active_win.title(): # mentor_win.activate() butt_x_y = gui.locateCenterOnScreen(f'mentor_imgs/trezorerie.png', confidence=CONF) sleep(0.1) if butt_x_y: gui.click(butt_x_y[0], butt_x_y[1]) pos_x_y = gui.position() gui.moveTo(pos_x_y[0], pos_x_y[1]) gui.press('down', 4, sleep_) gui.press('return', 1, sleep_) mv_mouse_cent() except IndexError: print('start mentor') @_printer def h_key12(): '''registru de banca''' # _date_ = gui.getWindow('LISTE - ') try: sleep(sleep_) act_win = gw.getActiveWindow() # dummy = gw.getWindowsWithTitle('MENTOR')[0] if mentor_user in act_win.title: mv_mouse_right() kb.press_and_release('ctrl+f10') # gui.press('f10') gui.press('right', 3, sleep_) gui.press('down', 1, 0.0) gui.press('down', 6, 0.0) gui.press('return', 1, sleep_) except IndexError: print('please activate Window LISTE') @_printer def bank_registry_val(): '''registru de banca val''' try: # mentor_win = gw.getWindowsWithTitle(mentor_user)[0] active_win = gw.getActiveWindowTitle() if mentor_user.title() in active_win.title(): # mentor_win.activate() butt_x_y = gui.locateCenterOnScreen(f'mentor_imgs/trezorerie.png', confidence=CONF) sleep(0.1) if butt_x_y: gui.click(butt_x_y[0], butt_x_y[1]) pos_x_y = gui.position() gui.moveTo(pos_x_y[0], pos_x_y[1]) gui.press('down', 6, 0.0) gui.press('return', 1, sleep_) mv_mouse_cent() except IndexError: print('start mentor') def close_all_lists(): '''inchide toate ferestrele''' try: # mentor_win = gw.getWindowsWithTitle(mentor_user)[0] active_win = gw.getActiveWindowTitle() if mentor_user.title() in active_win.title(): # mentor_win.activate() butt_x_y = gui.locateCenterOnScreen(f'mentor_imgs/inchidere.png', confidence=CONF) sleep(0.1) if butt_x_y: gui.click(butt_x_y[0], butt_x_y[1]) pos_x_y = gui.position() gui.moveTo(pos_x_y[0], pos_x_y[1]) mv_mouse_cent() except IndexError: pass @_printer def product_details(): '''fisa de magazie''' # _date_ = gui.getWindow('LISTE - ') try: # mentor_win = gw.getWindowsWithTitle(mentor_user)[0] active_win = gw.getActiveWindowTitle() if mentor_user.title() in active_win.title(): # mentor_win.activate() butt_x_y = gui.locateCenterOnScreen(f'mentor_imgs/stocuri.png', confidence=CONF) sleep(0.1) if butt_x_y: gui.click(butt_x_y[0], butt_x_y[1]) pos_x_y = gui.position() gui.moveTo(pos_x_y[0], pos_x_y[1]) gui.press('right', 1, sleep_) gui.press('return', 1, sleep_) mv_mouse_cent() except IndexError: print('start mentor') @_printer def h_key14(): '''inventar centralizat''' # _date_ = gui.getWindow('LISTE - ') try: sleep(sleep_) act_win = gw.getActiveWindow() # dummy = gw.getWindowsWithTitle('MENTOR')[0] if mentor_user in act_win.title: mv_mouse_right() kb.press_and_release('ctrl+f10') # gui.press('f10') gui.press('right', 1, sleep_) gui.press('down', 1, 0.0) gui.press('down', 8, 0.0) gui.press('right', 1, sleep_) gui.press('down', 7, 0.0) gui.press('return', 1, sleep_) except IndexError: print('please activate Window LISTE') @_printer def stocks(): '''stocuri pe gestiuni''' try: # mentor_win = gw.getWindowsWithTitle(mentor_user)[0] active_win = gw.getActiveWindowTitle() if mentor_user.title() in active_win.title(): # mentor_win.activate() butt_x_y = gui.locateCenterOnScreen(f'mentor_imgs/stocuri.png', confidence=CONF) sleep(0.1) if butt_x_y: gui.click(butt_x_y[0], butt_x_y[1]) pos_x_y = gui.position() gui.moveTo(pos_x_y[0], pos_x_y[1]) gui.press('down', 8, 0.0) gui.press('return', 1, sleep_) mv_mouse_cent() except IndexError: print('start mentor') @_printer def h_key16(): '''stocuri la terti''' # _date_ = gui.getWindow('LISTE - ') try: sleep(sleep_) act_win = gw.getActiveWindow() # dummy = gw.getWindowsWithTitle('MENTOR')[0] if mentor_user in act_win.title: mv_mouse_right() kb.press_and_release('ctrl+f10') # gui.press('f10') gui.press('right', 1, sleep_) gui.press('down', 1, 0.0) gui.press('down', 12, 0.0) gui.press('right', 1, sleep_) gui.press('return', 1, sleep_) except IndexError: print('please activate Window LISTE') @_printer def account_details(): '''fisa de cont''' try: # mentor_win = gw.getWindowsWithTitle(mentor_user)[0] active_win = gw.getActiveWindowTitle() if mentor_user.title() in active_win.title(): # mentor_win.activate() butt_x_y = gui.locateCenterOnScreen(f'mentor_imgs/contabile.png', confidence=CONF) sleep(0.1) if butt_x_y: gui.click(butt_x_y[0], butt_x_y[1]) pos_x_y = gui.position() gui.moveTo(pos_x_y[0], pos_x_y[1]) gui.press('down', 6, 0.0) gui.press('return', 1, sleep_) mv_mouse_cent() except IndexError: print('start mentor') @_printer def partner_balance(): '''fisa partener''' try: # mentor_win = gw.getWindowsWithTitle(mentor_user)[0] active_win = gw.getActiveWindowTitle() if mentor_user.title() in active_win.title(): # mentor_win.activate() butt_x_y = gui.locateCenterOnScreen(f'mentor_imgs/parteneri.png', confidence=CONF) sleep(0.1) if butt_x_y: gui.click(butt_x_y[0], butt_x_y[1]) pos_x_y = gui.position() gui.moveTo(pos_x_y[0], pos_x_y[1]) gui.press('down', 1, 0.0) gui.press('down', 8, 0.0) gui.press('return', 2, sleep_) mv_mouse_cent() except IndexError: print('start mentor') @_printer def salary(): '''stat de plata''' # mentor_win = gw.getWindowsWithTitle(mentor_user)[0] active_win = gw.getActiveWindowTitle() if mentor_user.title() in active_win.title(): # mentor_win.activate() butt_x_y = gui.locateCenterOnScreen(f'mentor_imgs/salarii.png', confidence=CONF) sleep(0.1) if butt_x_y: gui.click(butt_x_y[0], butt_x_y[1]) pos_x_y = gui.position() gui.moveTo(pos_x_y[0], pos_x_y[1]) gui.press('down', 1, sleep_) gui.press('right', 1, sleep_) gui.press('down', 3, sleep_) gui.press('return', 1, sleep_) mv_mouse_cent() # gui.move(1, 1) @_printer def sinteza(): '''contr. sinteza''' # mentor_win = gw.getWindowsWithTitle(mentor_user)[0] active_win = gw.getActiveWindowTitle() if mentor_user.title() in active_win.title(): # mentor_win.activate() butt_x_y = gui.locateCenterOnScreen(f'mentor_imgs/salarii.png', confidence=CONF) sleep(0.1) if butt_x_y: gui.click(butt_x_y[0], butt_x_y[1]) pos_x_y = gui.position() gui.moveTo(pos_x_y[0], pos_x_y[1]) gui.press('down', 19, 0.0) gui.press('right', 1, sleep_) gui.press('return', 1, sleep_) mv_mouse_cent() # gui.move(1, 1) @_printer def mod_salary(): '''mudul salarii''' # mentor_win = gw.getWindowsWithTitle(mentor_user)[0] active_win = gw.getActiveWindowTitle() if mentor_user.title() in active_win.title(): # mentor_win.activate() butt_x_y_1 = gui.locateCenterOnScreen(f'mentor_imgs/modul_salarii.png', confidence=CONF) butt_x_y_2 = gui.locateCenterOnScreen(f'mentor_imgs/modul_mentor.png', confidence=CONF) sleep(0.01) if butt_x_y_1: gui.click(butt_x_y_1[0], butt_x_y_1[1]) pos_x_y = gui.position() gui.moveTo(pos_x_y[0], pos_x_y[1]) elif butt_x_y_2: gui.click(butt_x_y_2[0], butt_x_y_2[1]) pos_x_y = gui.position() gui.moveTo(pos_x_y[0], pos_x_y[1]) mv_mouse_cent() @_printer def h_key19(): '''service structuri''' try: sleep(sleep_) declaratii = gw.getWindowsWithTitle('utilizator: master')[0] if declaratii.title in gw.getActiveWindowTitle(): mv_mouse_right() kb.press_and_release('control+f10') gui.press('down', 1, sleep_) gui.press('return', 1, sleep_) except IndexError: print('please activate Window LISTE') @_printer def h_key20(): '''vector d100''' try: sleep(sleep_) declaratii = gw.getWindowsWithTitle('utilizator: master')[0] if declaratii.title in gw.getActiveWindowTitle(): mv_mouse_right() kb.press_and_release('control+f10') gui.press('right', 1, sleep_) gui.press('down', 1, sleep_) gui.press('return', 1, sleep_) except IndexError: print('please activate Window LISTE') # ---> register shortcuts for winmentor # temporary disabled until found new way (ciel vs. mentor) # ------------------------------------------------------------------------------- def main(): '''quick_hotkey_mzk''' # ---> register shortcuts for winmentor kb.register_hotkey('`+r+j', remake_journal, args=()) # refacere jurnal kb.register_hotkey('`+r+c', cash_registry, args=()) # casa kb.register_hotkey('`+c+z', clients_ron, args=()) # clienti kb.register_hotkey('`+b+v', verif_balance, args=()) # balanta verificare kb.register_hotkey('`+r+f', suppliers_ron, args=()) # ron furnizori kb.register_hotkey('`+d+f', suppliers_val, args=()) # deviza furnizori kb.register_hotkey('`+r+b', bank_registry_ron, args=()) # jurnal banca kb.register_hotkey('`+j+v', bank_registry_val, args=()) # jurnal banca valuta kb.register_hotkey('`+s+m', product_details, args=()) # stoc fisa magazie # kb.register_hotkey('`+s+c', h_key14, args=()) # stoc centralizat kb.register_hotkey('`+c+s', sinteza, args=()) # contributii sinteza kb.register_hotkey('`+s+g', stocks, args=()) # stoc gestiuni kb.register_hotkey('`+s+t', h_key16, args=()) # stoc terti kb.register_hotkey('`+f+x', account_details, args=()) # fisa cont kb.register_hotkey('`+f+t', partner_balance, args=()) # fisa terti kb.register_hotkey('control+q', close_all_lists, args=()) # close all lists kb.register_hotkey('`+s+p', salary, args=()) # stat de plata # kb.register_hotkey('`+q', h_key19(), args=()) # service structuri # kb.register_hotkey('`+w', h_key20(), args=()) # vector d100 # ---> register shortcuts for users kb.register_hotkey('`+l', abbr, args=('`+l', r'EV1984nc-', '`')) kb.register_hotkey('c+l+a', abbr, args=('c+l+a', r'claudia.conta.ab@gmail.com')) kb.register_hotkey('v+d+e', abbr, args=('v+d+e', r'deeejas@gmail.com')) kb.register_hotkey('`+v+c', abbr, args=('`+v+c', r'ab6110398', '`')) kb.register_hotkey('`+v+d', abbr, args=('`+v+d', r'CV1984nc', '`')) kb.register_hotkey('`+p', abbr, args=('`+p', r'111555', '`')) # kb.register_hotkey('`+m+p', abbr, args=('`+m+p', r'mozaiq', '`')) kb.register_hotkey('`+r+p', abbr, args=('`+r+p', r'C0nsu1t1ng', '`')) # kb.add_hotkey('alt+win+2', lambda: sp.run('C:/Users/Levi/eclipse-workspace-2/vpn/win2016.rdp', shell=True)) # kb.add_hotkey('alt+win+3', lambda: sp.run('C:/Users/Levi/eclipse-workspace-2/vpn/abcons-vnc.rdp', shell=True)) # kb.add_hotkey('alt+win+4', lambda: sp.run('C:/Users/Levi/eclipse-workspace-2/vpn/AbCons_WIN10.bat', shell=True)) # kb.add_hotkey('alt+win+5', lambda: sp.run('C:/Users/Levi/eclipse-workspace-2/vpn/FER_WIN_SERV.vnc', shell=True)) kb.add_abbreviation('inc', 'incasat') kb.add_abbreviation('dee', 'deeejas@gmail.com') kb.add_abbreviation('lev', 'levente.marton@mzk.ro') kb.add_abbreviation('np', 'NN1984ord') passw = keyring.get_password('passman', 'deeejas@gmail.com') kb.add_abbreviation('bitw', passw) kb.add_abbreviation('mnt', 'mozaiq') kb.register_hotkey('`+9', mod_salary, args=()) # modul salarii kb.register_hotkey('alt+w', automate_write) # ---> block the program # kb.wait() # kb.register_hotkey('shift+space', abbr, args=(' ', '_')) # kb.register_hotkey('`+u', abbr, args=('`+u', r'mozaik129Mzk', '`')) # kb.register_hotkey('control+shift+0', enclose_pharenteses, args=()) # kb.register_hotkey('control+shift+]', enclose_list, args=()) # kb.register_hotkey('control+shift+`', enclose_dict, args=()) # kb.register_hotkey('control+k', indent_comment, args=()) if __name__ == '__main__': main()