123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- '''Created 16 Jan 2023 Levi'''
- import sys
- import traceback
- # import win32gui as wgui
- # import win32process as wproc
- # import win32api as wapi
- import keyboard as kb
- import pyautogui as gui
- import pywinctl as gw
- wnds = {'mzk': 'NextUp ERP - MOZAIK CONSULTING SRL',
- 'alp': 'NextUp ERP - ALPA SOLUTION SRL',
- 'east': 'NextUp ERP - ASOCIATIA CULTURALA GITAR EAST',
- 'srv': 'NextUp ERP [Admirustrare Server]',
- 'ant': 'utilizator: Master',
- 'dec': 'utilizator: Declaratii'}
- def pretty_exc(exc):
- exc_type, _exc_obj, exc_tb = sys.exc_info()
- # fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
- for tb in list(traceback.format_exception(exc_type, _exc_obj, exc_tb)):
- print(tb)
- def set_focus(*argv):
- # if not argv:
- window_name = gui.prompt(text="Enter window name", title='wnd_name')
- window_name = window_name.lower()
- # else:
- # window_name = wnds[argv[0]]
- # handle = wgui.FindWindow(None, wnds[window_name])
- try:
- handle = gw.getWindowsWithTitle(wnds[window_name])
- except KeyError as exc_:
- pretty_exc(exc_)
- print()
- # print("Window `{0:s}` handle: 0x{1:016X}".format(wnds[window_name], handle))
- # if not handle:
- # print("Invalid window handle")
- # return
- # remote_thread, _ = wproc.GetWindowThreadProcessId(handle)
- # wproc.AttachThreadInput(wapi.GetCurrentThreadId(), remote_thread, True)
- # wgui.SetFocus(handle)
- # wgui.SetForegroundWindow(handle)
- try:
- handle[0].activate()
- except Exception as exc_:
- pretty_exc(exc_)
- def main():
- '''setfocus'''
- kb.register_hotkey('control+alt+w', set_focus, args=()) # set_focus
- # kb.wait()
- if __name__ == "__main__":
- # set_focus()
- # print("Python {0:s} {1:d}bit on {2:s}\n".format(" ".join(item.strip() for item in sys.version.split("\n")), 64 if sys.maxsize > 0x100000000 else 32, sys.platform))
- main()
- # kb.wait()
|