from time import sleep import keyboard as kb import pyautogui as gui import pywinctl as gw import re sleep_ = 0.05 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=0.05) gui.typewrite(abbr_message, interval=0.05) def enclose_pharenteses(): gui.hotkey('ctrl', 'x', interval=0.05) gui.press('(') gui.hotkey('ctrl', 'v') gui.press(')') def enclose_list(): gui.hotkey('ctrl', 'x', interval=0.05) gui.press('[') gui.hotkey('ctrl', 'v') gui.press(']') def enclose_dict(): gui.hotkey('ctrl', 'x', interval=0.05) gui.press('{') gui.hotkey('ctrl', 'v') gui.press('}') def indent_comment(): sleep(0.5) # gui.press('backspace', pause=0.01) # or with esc-> backspace 2 and c+l key gui.press('end', pause=0.01) gui.press('home', pause=0.01) gui.hotkey('shift', '3') gui.press('space', pause=0.01) def mv_mouse_right(x=1919, y=598): gui.moveTo(x, y) def _printer(func): def wrapper(): print(func.__doc__, 'h_key performed') return func() return wrapper def h_key(): '''mentor list config''' gui.keyDown('shift') gui.press('tab', presses=9, interval=0.05) gui.keyUp('shift') sleep(0.5) gui.press('right', presses=1) @_printer def h_key2(): '''op''' # opfv = gui.getWindow('Form1') try: opfv = gw.getWindowsWithTitle('Form1')[0] opfv.maximize() opfv.restore() opfv.set_foreground() except IndexError: print('activate window Form1') # def h_key3(): # check_output(['start', 'c:/Users/conta1/git/Hello-World/omv/MyProjects/Win_gui/Mentor_gui.py'], shell=True) # def h_key4(): # check_output(['start', 'c:/Users/conta1/git/Hello-World/omv/MyProjects/Win_gui/Mentorgui_2.py'], shell=True) @_printer def h_key5(): '''refacere jurnal''' # _date_ = gui.getWindow('MENTOR') try: dummy = gw.getWindowsWithTitle('Utilizator: Master')[0] active_win = gw.getActiveWindowTitle() if dummy.title in active_win: try: dummy.activate() except Exception as e: print(str(e)) mv_mouse_right() kb.press_and_release('ctrl+f10') gui.press('right', 6, 0.05) gui.press('down', 1, 0.05) gui.press('return', 1, 0.05) except IndexError: print('please activate Window LISTE') @_printer def h_key6(): '''registru de casa''' try: dummy = gw.getWindowsWithTitle('Utilizator: Master')[0] active_win = gw.getActiveWindowTitle() if dummy.title in active_win: try: dummy.activate() except Exception as e: print(str(e)) mv_mouse_right() kb.press_and_release('ctrl+f10') gui.press('right', 3, 0.05) gui.press('down', 1, 0.05) gui.press('right', 1, 0.05) gui.press('return', 1, 0.05) except IndexError: print('please activate Window LISTE') @_printer def h_key7(): '''clienti datornici''' try: dummy = gw.getWindowsWithTitle('Utilizator: Master')[0] active_win = gw.getActiveWindowTitle() if dummy.title in active_win: try: dummy.activate() except Exception as e: print(str(e)) mv_mouse_right() kb.press_and_release('ctrl+f10') gui.press('right', 4, 0.05) gui.press('down', 1, 0.05) gui.press('right', 1, 0.05) gui.press('down', 10, 0.05) gui.press('return', 2, 0.05) except IndexError: print('please activate Window LISTE') @_printer def h_key8(): '''balanta de verificare''' try: dummy = gw.getWindowsWithTitle('Utilizator: Master')[0] active_win = gw.getActiveWindowTitle() if dummy.title in active_win: try: dummy.activate() except Exception as e: print(str(e)) mv_mouse_right() kb.press_and_release('ctrl+f10') gui.press('right', 6, 0.05) gui.press('down', 2, 0.05) gui.press('right', 1, 0.05) gui.press('down', 6, 0.05) gui.press('return', 2, 0.05) except IndexError: print('please activate Window LISTE') def h_key9(): '''furnizori neachitati''' try: dummy = gw.getWindowsWithTitle('Utilizator: Master')[0] active_win = gw.getActiveWindowTitle() if dummy.title in active_win: try: dummy.activate() except Exception as e: print(str(e)) mv_mouse_right() kb.press_and_release('ctrl+f10') gui.press('right', 4, 0.05) gui.press('down', 2, 0.05) gui.press('right', 1, 0.05) gui.press('down', 5, 0.05) gui.press('return', 2, 0.05) except IndexError: print('please activate Window LISTE') def h_key10(): '''furnizori neachitati valuta''' try: dummy = gw.getWindowsWithTitle('Utilizator: Master')[0] active_win = gw.getActiveWindowTitle() if dummy.title in active_win: try: dummy.activate() except Exception as e: print(str(e)) mv_mouse_right() kb.press_and_release('ctrl+f10') gui.press('right', 4, 0.05) gui.press('down', 2, 0.05) gui.press('right', 1, 0.05) gui.press('down', 6, 0.05) gui.press('return', 2, 0.05) except IndexError: print('please activate Window LISTE') @_printer def h_key11(): '''registru de banca''' try: dummy = gw.getWindowsWithTitle('Utilizator: Master')[0] active_win = gw.getActiveWindowTitle() if dummy.title in active_win: try: dummy.activate() except Exception as e: print(str(e)) mv_mouse_right() kb.press_and_release('ctrl+f10') gui.press('right', 3, 0.05) gui.press('down', 5, 0.05) gui.press('right', 1, 0.05) gui.press('return', 1, 0.05) except IndexError: print('please activate Window LISTE') @_printer def h_key12(): '''registru de banca''' try: dummy = gw.getWindowsWithTitle('Utilizator: Master')[0] active_win = gw.getActiveWindowTitle() if dummy.title in active_win: try: dummy.activate() except Exception as e: print(str(e)) mv_mouse_right() gui.press('right', 3, 0.05) gui.press('down', 7, 0.05) gui.press('return', 1, 0.05) except IndexError: print('please activate Window LISTE') @_printer def h_key13(): '''fisa de magazie''' try: dummy = gw.getWindowsWithTitle('Utilizator: Master')[0] active_win = gw.getActiveWindowTitle() if dummy.title in active_win: try: dummy.activate() except Exception as e: print(str(e)) mv_mouse_right() kb.press_and_release('ctrl+f10') gui.press('right', 1, 0.05) gui.press('down', 1, 0.05) gui.press('right', 1, 0.05) gui.press('return', 1, 0.05) except IndexError: print('please activate Window LISTE') @_printer def h_key14(): '''inventar centralizat''' try: dummy = gw.getWindowsWithTitle('Utilizator: Master')[0] active_win = gw.getActiveWindowTitle() if dummy.title in active_win: try: dummy.activate() except Exception as e: print(str(e)) mv_mouse_right() kb.press_and_release('ctrl+f10') gui.press('right', 1, 0.05) gui.press('down', 9, 0.05) gui.press('right', 1, 0.05) gui.press('down', 7, 0.05) gui.press('return', 1, 0.05) except IndexError: print('please activate Window LISTE') @_printer def h_key15(): '''stocuri pe gestiuni''' try: dummy = gw.getWindowsWithTitle('Utilizator: Master')[0] active_win = gw.getActiveWindowTitle() if dummy.title in active_win: try: dummy.activate() except Exception as e: print(str(e)) mv_mouse_right() kb.press_and_release('ctrl+f10') gui.press('right', 1, 0.05) gui.press('down', 9, 0.05) gui.press('right', 1, 0.05) gui.press('return', 1, 0.05) # gui.press('down', 7, 0.05) # gui.press('return', 1, 0.05) except IndexError: print('please activate Window LISTE') @_printer def h_key16(): '''stocuri la terti''' try: dummy = gw.getWindowsWithTitle('Utilizator: Master')[0] active_win = gw.getActiveWindowTitle() if dummy.title in active_win: try: dummy.activate() except Exception as e: print(str(e)) mv_mouse_right() kb.press_and_release('ctrl+f10') gui.press('right', 1, 0.05) gui.press('down', 13, 0.05) gui.press('right', 1, 0.05) gui.press('return', 1, 0.05) # gui.press('down', 7, 0.05) # gui.press('return', 1, 0.05) except IndexError: print('please activate Window LISTE') @_printer def h_key17(): '''lista fisa de cont''' # _date_ = gui.getWindow('MENTOR') try: dummy = gw.getWindowsWithTitle('Utilizator: Master')[0] active_win = gw.getActiveWindowTitle() if dummy.title in active_win: try: dummy.activate() except Exception as e: print(str(e)) mv_mouse_right() kb.press_and_release('ctrl+f10') gui.press('right', 6, 0.05) gui.press('down', 5, 0.05) gui.press('right', 1, 0.05) gui.press('return', 1, 0.05) # gui.press('down', 7, 0.05) # gui.press('return', 1, 0.05) except IndexError: print('please activate Window LISTE') @_printer def h_key18(): '''lista fisa pertener''' try: dummy = gw.getWindowsWithTitle('Utilizator: Master')[0] active_win = gw.getActiveWindowTitle() if dummy.title in active_win: try: dummy.activate() except Exception as e: print(str(e)) mv_mouse_right() kb.press_and_release('ctrl+f10') gui.press('right', 4, 0.05) gui.press('down', 10, 0.05) gui.press('right', 1, 0.05) gui.press('return', 1, 0.05) except IndexError: print('please activate Window LISTE') @_printer def h_key19(): '''service structuri''' try: declaratii = gw.getWindowsWithTitle('DECLARATII')[0] if declaratii.title in gw.getActiveWindowTitle(): mv_mouse_right() kb.press_and_release('control+f10') gui.press('down', 1, 0.05) gui.press('return', 1, 0.05) except IndexError: print('please activate Window LISTE') @_printer def h_key20(): '''vector d100''' try: declaratii = gw.getWindowsWithTitle('DECLARATII')[0] if declaratii.title in gw.getActiveWindowTitle(): mv_mouse_right() kb.press_and_release('control+f10') gui.press('right', 1, 0.05) gui.press('down', 1, 0.05) gui.press('return', 1, 0.05) except IndexError: print('please activate Window LISTE') # register shortcuts for users #------------------------------------------------------------------------------------ # kb.register_hotkey('alt+`', lambda: h_key2()) # kb.register_hotkey('`+r+j', lambda: h_key5()) # kb.register_hotkey('`+r+c', lambda: h_key6()) # kb.register_hotkey('`+c', lambda: h_key7()) # kb.register_hotkey('`+b', lambda: h_key8()) # kb.register_hotkey('`+r+f', lambda: h_key9()) # kb.register_hotkey('`+v+f', lambda: h_key10()) # kb.register_hotkey('`+j+b', lambda: h_key11()) # kb.register_hotkey('`+j+v', lambda: h_key12()) # kb.register_hotkey('`+s+m', lambda: h_key13()) # kb.register_hotkey('`+s+c', lambda: h_key14()) # kb.register_hotkey('`+s+g', lambda: h_key15()) # kb.register_hotkey('`+s+t', lambda: h_key16()) # kb.register_hotkey('`+d', lambda: h_key17()) # kb.register_hotkey('`+f+t', lambda: h_key18()) #------------------------------------------------------------------------------------ # 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('d+e', abbr, args=('d+e', r'deeejas@gmail.com')) # kb.register_hotkey('`+p', abbr, args=('`+p', r'111555', '`')) # kb.register_hotkey('`+m', abbr, args=('`+m', r'mozaiq', '`')) # 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=()) # or with c+l key if __name__ == '__main__': kb.wait()