Esempio n. 1
0
 def _get_data_from_panel(self, panel, title, refresh=False):
     result = []
     rect = panel.rectangle()
     if refresh:
         x, y = rect.right - 85, (rect.top + rect.bottom) // 2
         mouse.move(coords=(x, y))
         mouse.click(coords=(x, y))
         time.sleep(0.5)
     x, y = rect.right - 20, (rect.top + rect.bottom) // 2
     mouse.move(coords=(x, y))
     mouse.click(coords=(x, y))
     time.sleep(1.5)
     self.app.top_window().type_keys("^C", set_foreground=False)
     self.app.top_window().type_keys("%{s}%{y}", set_foreground=False)
     time.sleep(1)
     #
     try:
         file_name = pywinauto.clipboard.GetData()
         #
         data = xlrd.open_workbook('C:\\Users\\Administrator\\Desktop\\%s' %
                                   file_name,
                                   encoding_override='GBK')
         table = data.sheets()[0]
         #
         nrows = table.nrows
         for i in range(nrows):
             # print(table.row_values(i))
             result.append(table.row_values(i))
     # pylint: disable=broad-except
     except Exception as e:
         print(e)
     #
     return result
Esempio n. 2
0
def TDX_OpenDataOutput():
    app = application.Application()
    tool_name = r'C:\十档行情\tdxw.exe'
    window_name = '通达信金融终端通赢版V7.47'
    app.start(tool_name)
    app.connect(path=tool_name)
    mouse.move([985, 420])
    mouse.click('left', [990, 422])  #左键在什么位置点击
    time.sleep(10)  #休息8秒,等等数据初始化加载
    # app.GetCursorPos()
    #点击A股,导出所有A股早盘数据
    mouse.click('left', [970, 990])
    ###点击选项数据导出,导出数据
    mouse.click('left', [1608, 11])
    mouse.click('left', [1655, 404])
    time.sleep(1)
    mouse.click('left', [827, 397])
    mouse.click('left', [1055, 547])
    time.sleep(1)
    mouse.click('left', [1110, 653])

    time.sleep(50)
    #点击取消,完成导出
    mouse.click('left', [1035, 583])
    time.sleep(1)
    ###########导出版块早盘数据
    # 点击版本块指数,导出所有版块数据
    mouse.click('left', [710, 995])
    mouse.click('left', [42, 67])
    ###点击选项数据导出,导出数据
    mouse.click('left', [1608, 11])
    mouse.click('left', [1655, 404])
    time.sleep(1)
    mouse.click('left', [827, 397])
    mouse.click('left', [1055, 547])
    time.sleep(1)
    mouse.click('left', [1110, 653])

    time.sleep(10)
    # 点击取消,完成导出
    mouse.click('left', [1016, 580])
    # 点击分类--》沪深主要指数,导出所有指数数据

    mouse.click('left', [86, 796])
    mouse.click('left', [119, 626])

    ###点击选项数据导出,导出数据
    mouse.click('left', [86, 794])
    mouse.click('left', [131, 625])
    time.sleep(1)
    mouse.click('left', [827, 397])
    mouse.click('left', [1055, 547])
    time.sleep(1)
    mouse.click('left', [1110, 653])

    time.sleep(10)
    # 点击取消,完成导出
    mouse.click('left', [1016, 580])
Esempio n. 3
0
def add_TCP_Signal(window_name):
    ms.press(button='left', coords=(902, 456))
    ms.move(coords=(940, 456))
    ms.release(button='left', coords=(940, 456))
    app._wait_child(window_name, u'编辑__信号__signal', 'ready', 10, 2)
    app.click(window_name, 'ComboBox5')
    time.sleep(1)
    app.input(window_name, 'ComboBox5', 'i_block')  #添加数据结构
    app.click(window_name, u'确定')   #确定
    app._wait_not_child(window_name, u'编辑__信号__signal', 'ready', 10, 2)
Esempio n. 4
0
def add_TCP_Signal(window_name):
    ms.press(button='left', coords=(902, 456))
    ms.move(coords=(940, 456))
    ms.release(button='left', coords=(940, 456))
    app._wait_child(window_name, u'信号编辑对话框', 'ready', 10, 2)
    app.click(window_name, 'ComboBox5')
    app.input(window_name, 'ComboBox5', 'i_block')#添加数据结构
    app.Sendk('ENTER', 1)
    app.click(window_name, u'确定')#确定
    app._wait_not_child(window_name, u'信号编辑对话框', 'ready', 10, 2)
Esempio n. 5
0
    def setUp(self):
        """Set some data and ensure the application is in the state we want"""
        Timings.defaults()

        self.tm = _ready_timeout
        app = Application(backend='win32')
        app.start(os.path.join(mfc_samples_folder, u"TrayMenu.exe"), wait_for_idle=False)
        self.app = app
        self.dlg = app.top_window()
        mouse.move((-500, 200))  # remove the mouse from the screen to avoid side effects
        self.dlg.wait('ready', timeout=self.tm)
Esempio n. 6
0
    def appShow_or_Hide(self, gui):
        try:
            # 既にKeasyウィンドウが非表示だった場合
            if gui.isHidden():
                # 吹っ飛ぶ前のマウス位置を記憶======================
                win32functions.GetCursorPos(byref(self.mousePos_pointer))
                beforeX = self.mousePos_pointer.x
                beforeY = self.mousePos_pointer.y
                # time.sleep(0.01)  # 一旦止めないと不自然な挙動をする
                # ブラウザを開いていれば,URLからアカウントを一時保存
                self.autoMemorize(gui)
                # トレイ格納時のウィンドウサイズに戻す
                if self.savedMyGeometry != None:
                    gui.restoreGeometry(self.savedMyGeometry)
                gui.show()  # ウィンドウ表示
                self.thisWindowWrapper.set_focus()  # アクティブにする+フォーカスする
                move(coords=(beforeX, beforeY))  # マウスを移動し直す
                gui.console.setFocus()  # コンソールにフォーカス(カーソル表示)
            # Keasyウィンドウが表示されている場合
            else:
                # 吹っ飛ぶ前のマウス位置を記憶======================
                win32functions.GetCursorPos(byref(self.mousePos_pointer))
                beforeX = self.mousePos_pointer.x
                beforeY = self.mousePos_pointer.y
                time_sleep(0.01)  # 一旦止めないと不自然な挙動をする
                # 開いているウィンドウのハンドル一覧を取得
                windowHandles = self.getWindowHandles()
                for i in range(len(windowHandles) - 1):
                    # 最後面以外のどこかにKeasyウィンドウがあれば,
                    # Keasyの次のウィンドウにフォーカス
                    if windowHandles[i] == self.thisHandle:
                        # 次ウィンドウのハンドル取得
                        nextWindow = hwndwrapper.HwndWrapper(windowHandles[i +
                                                                           1])
                        nextWindow.set_focus()  # 次ウィンドウにフォーカス
                        break

                # Keasyウィンドウが最後面だった場合は,
                # Keasyの前のウィンドウにフォーカス
                if windowHandles[len(windowHandles) - 1] == self.thisHandle:
                    # 前ウィンドウのハンドル取得
                    previousWindow = hwndwrapper.HwndWrapper(
                        windowHandles[(len(windowHandles) - 1) - 1])
                    previousWindow.set_focus()  # 前ウィンドウにフォーカス
                # 格納時のウィンドウサイズを記憶
                self.savedMyGeometry = gui.saveGeometry()
                gui.hide()  # ウィンドウ非表示
                move(coords=(beforeX, beforeY))  # マウスを移動し直す
        except:
            traceback.print_exc()
Esempio n. 7
0
def add_TCP_Case(window_name):
    app.click(window_name, u'测试用例')
    app._wait_child(window_name, u'测试用例集', 'ready', 10, 2)
    app.right_click(window_name, 'TreeView2')
    app.Sendk('DOWN', 2)
    app.Sendk('ENTER',1)
    app._wait_child(window_name, u'新建用例分类', 'ready', 10, 2)
    app.click(window_name, u'确定')
#     app._wait_not_child(window_name, u'新建用例分类', 'ready', 10, 2)
    app._wait_child(window_name, u'用例分类', 'ready', 10, 2)
    app.right_click(window_name,u'用例分类') #测试用例root
    time.sleep(1)
    app.Sendk('DOWN',4)
    app.Sendk('ENTER',1)
    app._wait_child(window_name, u'新建测试用例', 'ready', 10, 2)
    app.Sendk('TAB',2)
    app.input(window_name, 'Edit1', 'content2')#输入用例名
    app.click(window_name,u'确定') #确定
    app.click(window_name,u'用例分类')
    app.Sendk('RIGHT',1)
    app.Sendk('DOWN',1)
    app._wait_child(window_name, 'content2', 'ready', 10, 2)
    

#添加信号
    app.click(window_name, u'测试用例变量')
    app.click(window_name, 'Button16')
    app._wait_child(window_name, u'选择信号对话框', 'ready', 10, 2)
    ms.click(coords=(610,470))#复选信号
    app.click(window_name, 'Button14')#确定
    app._wait_child(window_name, u'signal', 'ready', 10, 2)


#测试用例编辑    
    app.click(window_name, u'测试用例编辑')
    app.right_click(window_name, 'TreeItem16')
    app.Sendk('UP', 1)
    app.Sendk('ENTER', 1)#快速生成
    app._wait_child(window_name, u'删除', 'ready', 10, 2)
    ms.press(button='left',coords=(600,229))
    ms.move(coords=(661, 646))
    ms.release(button='left', coords=(661, 646))
    app.click(window_name, u'确定')
    app._wait_child(window_name, u'发送[signal]', 'ready', 10, 2)
Esempio n. 8
0
    def auto_ipo(self):
        self._switch_left_menus(["新股申购", "今日申购"])
        #
        btn = self._main.child_window(title='批量申购', class_name="TspSkinButton")
        rect = btn.rectangle()
        x, y = (rect.left + rect.right) // 2, (rect.top + rect.bottom) // 2
        mouse.move(coords=(x, y))
        mouse.click(coords=(x, y))
        self.wait(1)
        self._app.top_window().type_keys('%{U}')
        self.wait(1)
        btn = self._app.top_window().child_window(title='确认申购',
                                                  class_name="TspSkinButton")
        rect = btn.rectangle()
        x, y = (rect.left + rect.right) // 2, (rect.top + rect.bottom) // 2
        mouse.move(coords=(x, y))
        mouse.click(coords=(x, y))

        return self._handle_pop_dialogs(
            handler_class=pop_dialog_handler.EnterDialogHandler)
Esempio n. 9
0
def add_TCP_Signal(window_name):
    app.click(window_name, 'Pane2')
    x=py.position()[0]
    y=py.position()[1]
    x_left=x-174
    y_left=y-13
    x_right=x-135
    y_right=y-13
#     ms.press(button='left', coords=(902, 456))
#     ms.move(coords=(940, 456))
#     ms.release(button='left', coords=(940, 456))
    ms.press(button='left', coords=(x_left,y_left))
    ms.move(coords=(x_right,y_right))
    ms.release(button='left', coords=(x_right,y_right))
    app._wait_child(window_name, u'编辑__信号__signal', 'ready', 10, 2)
    app.click(window_name, 'ComboBox5')
    time.sleep(1)
    app.input(window_name, 'ComboBox5', 'i_block')  #添加数据结构
    app.click(window_name, u'确定')   #确定
    app._wait_not_child(window_name, u'编辑__信号__signal', 'ready', 10, 2)
Esempio n. 10
0
 def _cancel_entrust_by_double_click(self, row):
     x = self._config.CANCEL_ENTRUST_GRID_LEFT_MARGIN
     y = (self._config.CANCEL_ENTRUST_GRID_FIRST_ROW_HEIGHT +
          self._config.CANCEL_ENTRUST_GRID_ROW_HEIGHT * row)
     panel = self._main.child_window(title='bgpanel',
                                     class_name='TspSkinPanel')
     panel.child_window(
         title='', class_name="TAdvStringGrid").double_click(coords=(x, y))
     self.wait(0.2)
     # 等待出现 确认兑换框
     if self.is_exist_pop_dialog():
         # 点击是 按钮
         w = self._app.top_window()
         if w is not None:
             btn = w["确定"]
             if btn is not None:
                 btn.click()
                 rc = btn.rectangle()
                 x, y = (rc.left + rc.right) // 2, (rc.top + rc.bottom) // 2
                 mouse.move(coords=(x, y))
                 mouse.click(coords=(x, y))
                 self.wait(0.2)
Esempio n. 11
0
    def login(self, user, password, exe_path, comm_password=None, **kwargs):
        """
        :param user: 用户名
        :param password: 密码
        :param exe_path: 客户端路径, 类似
        :param comm_password:
        :param kwargs:
        :return:
        """
        self._editor_need_type_keys = False

        try:
            self._app = pywinauto.Application().connect(
                path=exe_path, timeout=3
            )
            self._close_prompt_windows()
            lock_win = self._app.window(title=" 富易交易")
            if lock_win.exists() and lock_win.is_visible():
                lock_win.print_ctrl_ids()
                SetForegroundWindow(lock_win.wrapper_object())
                rect = lock_win.child_window(title="解锁", class_name="TspSkinButton").rectangle()
                x, y = (rect.left + rect.right) // 2, (rect.top + rect.bottom) // 2
                mouse.move(coords=(x, y))
                mouse.click(coords=(x, y))
                self.wait(1)
                passedit = self._app.window(title="-%s" % user).child_window(title="", class_name="TFyPassEdit")
                passedit.select()
                for k in password:
                    keyboard.send_keys('{VK_NUMPAD%s}' % k)
                keyboard.send_keys('{ENTER}')
            self.wait(1)
            self._main = self._app.window(title="富易 - %s" % user, class_name='TMainForm')
            self.wait(1)
        # pylint: disable=broad-except
        except Exception as e:
            self._app = pywinauto.Application().start(exe_path)
            self.wait(1)
Esempio n. 12
0
 def _switch_left_menus(self, path, sleep=0.2):
     self.close_pop_dialog()
     self._app.top_window().type_keys('{F8}')
     rect = self._get_left_menus_handle().rectangle()
     x, y = (rect.left + rect.right) // 2, rect.top + 100
     mouse.move(coords=(x, y))
     mouse.click(coords=(x, y))
     self.wait(sleep)
     z = y + 30
     mouse.move(coords=(x, z))
     mouse.click(coords=(x, z))
     self.wait(sleep)
     try:
         btn = self._main.child_window(title='批量申购',
                                       class_name="TspSkinButton")
         btn.print_ctrl_ids()
     except Exception as e:
         print('异常', e)
         mouse.move(coords=(x, y))
         mouse.click(coords=(x, y))
         self.wait(sleep)
         mouse.move(coords=(x, z))
         mouse.click(coords=(x, z))
         self.wait(sleep)
Esempio n. 13
0
def execute_command(parameters, app_obj, window_obj):

    traces = parameters["traces"]
    backend = parameters["backend"]
    app_dict = parameters["app_dict"]
    main_window_dict = parameters["main_window_dict"]
    child_window_dict = parameters["child_window_dict"]
    command = parameters["command"]
    value = parameters["value"]
    hover = parameters["hover"]
    wait = parameters["wait"]

    try:
        if "PRINT" in command.upper():
            if traces is True:
                print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                      ": " + "=== * Print control identifiers start * ===")

            if "FILE" in command.upper():
                if value is not "":
                    value = r"C:\print_control_identifiers.txt"

                if traces is True:
                    print(
                        datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                        ": " + "\tPrinting control identifiers to file: " +
                        str(value))

                window_obj.print_control_identifiers(filename=str(value))

            elif value is not "" and value.isdigit():
                if traces is True:
                    print(
                        datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                        ": " +
                        "\tPrinting control identifiers to output variable with depth: "
                        + str(value))

                window_obj.print_control_identifiers(depth=int(value))

            else:
                if traces is True:
                    print(
                        datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                        ": " +
                        "\tPrinting control identifiers to output variable...")

                window_obj.print_control_identifiers()

            if traces is True:
                print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                      ": " + "\tPrinting control identifiers complete!")
                print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                      ": " + "=== * Print control identifiers end * ===")

        elif command.upper() == "WAIT":
            if traces is True:
                print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                      ": " + "=== * Waiting for control start * ===")

            success = True

            try:
                if traces is True:
                    print(
                        datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                        ": " + "\tWaiting for the control to exist for " +
                        str(wait) + " seconds...")

                window_obj.wait("exists",
                                timeout=int(wait),
                                retry_interval=0.25)

            except:
                success = False

            if success is False:
                return "Error: Element did not appear!"

            if traces is True:
                print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                      ": " + "\tControl exists!")
                print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                      ": " + "=== * Waiting for control end * ===")

        elif command.upper() == "LOCATION":
            if traces is True:
                print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                      ": " + "=== * Print location start * ===")

            window_obj.print_control_identifiers(depth=1)

            if traces is True:
                print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                      ": " + "=== * Print location end * ===")

        elif "CLICK" in command.upper():
            if traces is True:
                print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                      ": " + "=== * Perform click command start * ===")

            mouse_location_x, mouse_location_y = win32api.GetCursorPos()

            if command.upper() == "CLICK":
                if traces is True:
                    print(
                        datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                        ": " + "\tAttempting to click...")

                window_obj.click_input()

                if traces is True:
                    print(
                        datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                        ": " + "\tClick complete!")

            elif command.upper() == "DOUBLECLICK":
                if traces is True:
                    print(
                        datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                        ": " + "\tAttempting to double-click...")

                window_obj.click_input(double=True)

                if traces is True:
                    print(
                        datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                        ": " + "\tDouble-click complete!")

            elif command.upper() == "RIGHTCLICK":
                if traces is True:
                    print(
                        datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                        ": " + "\tAttempting to right-click...")

                window_obj.click_input(button="right")

                if traces is True:
                    print(
                        datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                        ": " + "\tRight-click complete!")

            if traces is True:
                print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                      ": " + "=== * Perform click command end * ===")
                print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                      ": " +
                      "=== * Move mouse back to original position start * ===")

            if hover is False:
                if traces is True:
                    print(
                        datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                        ": " +
                        "\tAttempting to move mouse back to position...")

                mouse.move((mouse_location_x, mouse_location_y))

                if traces is True:
                    print(
                        datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                        ": " + "\tMoving mouse back to position complete!")

            else:
                if traces is True:
                    print(
                        datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                        ": " +
                        "\tHovering mouse activated, therefore, do NOT move mouse back in position"
                    )

            if traces is True:
                print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                      ": " +
                      "=== * Move mouse back to original position end * ===")

        elif "SEND" in command.upper():
            if traces is True:
                print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                      ": " + "=== * Perform send command start * ===")
                print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                      ": " + "\tAttempting to write values: " + str(value))

            window_obj.type_keys(value,
                                 with_spaces=True,
                                 with_tabs=True,
                                 with_newlines=True)

            if traces is True:
                print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                      ": " + "\tWriting values complete!")
                print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                      ": " + "=== * Perform send command end * ===")

        elif "SELECT" in command.upper():
            if traces is True:
                print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                      ": " + "=== * Perform select command start * ===")

            if value.startswith("item=") and value[5:].isdigit():
                if traces is True:
                    print(
                        datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                        ": " +
                        "\tValue is digit, therefore, convert to integer")

                value = int(int(value[5:]) - 1)

            if traces is True:
                print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                      ": " + "\tAttempting to select item: " + str(value))

            window_obj.select(value)

            if traces is True:
                print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                      ": " + "\tSelecting value complete!")
                print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                      ": " + "=== * Perform select command end * ===")

        return True

    except:
        print(traceback.format_exc())
        return "ERROR: Unexpected issue!"
# Screen resolution
x = round(root.winfo_screenwidth() * 0.92)
y = round(root.winfo_screenheight() * 0.92)

# Open VPN connection
# Open browser with tab(s) from with randome links
app = Application(backend='uia').start(brave_dir +
                                       ' --force-renderer-accessibility ' +
                                       link_random)
#app = Application().connect(path=brave_dir)
app.window()
i = 1
for i in range(1, 120):
    j = 1
    for j in range(1, 15):
        mouse.move(coords=(x, y))
        pywinauto.mouse.click(button='left', coords=(x, y))
        time.sleep(20)
        j = j + 1
    print(str(i) + ' ' + str(x) + ' ' + str(y))
    # go to tab 1 and close it
    # random link
    link_random = random.choice(lines)
    #return app to top window
    app.window()
    # open link
    app = Application(backend='uia').start(brave_dir + ' ' + link_random)
    send_keys('^a^1')
    send_keys('^a^w')

    i = i + 1
Esempio n. 15
0
def click_button(pic_name):
    button_down_pixel = pa.locateOnScreen(pic_name)
    x, y = pa.center(button_down_pixel)
    move(coords=(x, y))
    click(coords=(x, y))
Esempio n. 16
0
                        time.sleep(git_wait)
                        git_app.fatty.type_keys("^b{DOWN}")
                        time.sleep(git_wait)

                    git_app.fatty.type_keys("^b{LEFT}")
                    time.sleep(git_wait)

                    for _ in range(n_git_panes):
                        git_app.fatty.type_keys("{UP}~")
                        git_app.fatty.type_keys("./gitu.bat{VK_SPACE}f")
                        time.sleep(git_wait)
                        git_app.fatty.type_keys("^b{DOWN}")
                        time.sleep(git_wait)
                print('done')

        mouse.move(coords=(mouse_x, mouse_y))

    elif config == 1:
        servers_app.fatty.type_keys("t~")
        servers_app.fatty.type_keys("^+t")
        servers_app.fatty.type_keys("f~")
        servers_app.fatty.type_keys("^+t")
        servers_app.fatty.type_keys("sstg{VK_SPACE}tb~")
        servers_app.fatty.type_keys("sudo{VK_SPACE}-s~")
        servers_app.fatty.type_keys("%s~" % pwd0)
        time.sleep(2)

        if config == 0:
            servers_app.fatty.type_keys(
                "tmux{VK_SPACE}attach{VK_SPACE}-d{VK_SPACE}-t{VK_SPACE}grs~")
        else:
Esempio n. 17
0
        coord = tuple(int(c) for c in coord.split(","))
        click[option](button=type_, coords=coord)

    except Exception as e:
        print("\x1B[" + "31;40mError\u2193\x1B[" + "0m")
        PrintException()
        raise e

if module == "move":
    coord = GetParams("coord")

    try:
        coord = tuple(int(c) for c in coord.split(","))
        print(coord)
        mouse.move(coords=coord)

    except Exception as e:
        print("\x1B[" + "31;40mError\u2193\x1B[" + "0m")
        PrintException()
        raise e

if module == "scroll":
    coord = GetParams("coord")
    dist = GetParams("dist")

    try:

        coord = tuple([int(c) for c in coord.split(",")])
        mouse.scroll(coords=coord, wheel_dist=int(dist))
Esempio n. 18
0
    def openwu(self):
        if self.wu == None:
            print("wu is None")
            return
        '''
        查找弹出的对话框
        '''
        winlist = {}
        for a in self.dlg.children():
            winlist[a.class_name()] = a
        if "TFrmFunction" in winlist.keys():
            self.func = winlist["TFrmFunction"]
        else:
            # 如果窗口没有显示,就点击无字
            x = self.wu.rectangle().left
            x = x + random.randint(5, 20)
            y = self.wu.rectangle().top
            y = y + random.randint(5, 20)
            mouse.move(coords=(x, y))
            mouse.click(coords=(x, y))
            ##            print("======")
            for a in self.dlg.children():
                if a.class_name() == "TFrmFunction":
                    self.func = a
                    break
        # tab标签页
        for b in self.func.children()[0].children():
            if b.class_name() == "TPageControl":
                self.tab = b
##                print("self.tab:",self.tab.class_name())
            for c in self.tab.children():
                ##                print("c=",c.texts())
                if c.class_name() == "msctls_updown32":
                    self.d = c

                    x = self.d.rectangle().left
                    x = x + random.randint(5, 10)
                    y = self.d.rectangle().top
                    y = y + random.randint(5, 10)
                    mouse.move(coords=(x, y))
                    mouse.click(coords=(x, y))
                    mouse.click(coords=(x, y))

                    x = self.d.rectangle().left
                    x = x + random.randint(5, 10) + 20
                    y = self.d.rectangle().top
                    y = y + random.randint(5, 10)
                    mouse.move(coords=(x, y))
                    mouse.click(coords=(x, y))
                    mouse.click(coords=(x, y))

                if c.texts()[0] == "其他":
                    self.qita = c
                    ##                    print("qita=",self.qita.texts())
                    x = self.qita.rectangle().left
                    x = x + random.randint(5, 10)
                    y = self.qita.rectangle().top
                    y = y + random.randint(5, 10)
                    mouse.move(coords=(x, y))
                    mouse.click(coords=(x, y))
        for a in self.tab.children():
            for b in a.children():
                ##                print(b.class_name())
                if b.class_name() == "TGroupBox":
                    for c in b.children():
                        ##                        print(c.class_name())
                        ##                        print(c.texts())
                        if c.class_name() == "TButton":
                            self.killset = c
                        if c.texts()[0] == "自动杀怪":
                            self.autokillcb = c
                    cl = b.children()
                    self.huticb = cl[0]
                    self.point = cl[2]
                    self.pointlist = cl[3]
                    self.monster = cl[4]
                    self.monsterlist = cl[5]
                    self.autokillcb = cl[6]
Esempio n. 19
0
def main():
    params = Params()
    paramparse.process(params)

    in_txt = copy_from_clipboard()
    if in_txt is None:
        lines = []
    else:
        lines = in_txt.split('\n')
        lines = [line.strip() for line in lines if line.strip()]

    if lines:
        is_path = all(
            line.startswith('"') and line.endswith('"') for line in lines)
        if is_path:
            stripped_lines = [line.strip('"') for line in lines]
        else:
            stripped_lines = lines[:]

        try:
            is_ogg = all(line.endswith('.ogg') for line in stripped_lines)
            is_folder = all(os.path.isdir(line) for line in stripped_lines)
        except BaseException as e:
            print('exception during ogg / folder check : {}'.format(e))
            is_ogg = 0
            is_folder = 0

        print('is_ogg: {}'.format(is_ogg))
        print('stripped_lines: {}'.format(stripped_lines))
        print('lines: {}'.format(lines))
        #
        # input('press any key')

        if is_ogg:
            process_ogg(stripped_lines,
                        lines,
                        params.category,
                        is_path,
                        params.cmd,
                        pause_for_input=1)
            return
        elif is_folder:
            stripped_lines.sort()
            for folder in stripped_lines:
                ogg_paths = [
                    '{}'.format(os.path.join(folder, k))
                    for k in os.listdir(folder) if k.endswith('.ogg')
                ]
                ogg_lines = ['"{}"'.format(k) for k in ogg_paths]
                process_ogg(ogg_paths,
                            ogg_lines,
                            params.category,
                            is_path,
                            params.cmd,
                            pause_for_input=0)
            return
        else:
            try:
                out_txt = process(in_txt)
            except:
                pass
            else:
                copy_to_clipboard(out_txt, print_txt=1)
                time.sleep(0.5)
                return

    if params.ffs.enable:
        for _ffs_file in params.ffs.files:
            ffs_path = os.path.join(params.ffs.root,
                                    _ffs_file + '.' + params.ffs.ext)
            ffs_cmd = '{} "{}"'.format(params.ffs.exe, ffs_path)
            print(ffs_cmd)
            os.system(ffs_cmd)

    if params.txt_path:

        assert os.path.isdir(params.txt_path), "invalid text path: {}".format(
            params.txt_path)

        if params.recursive:
            files_gen = [[
                linux_path(dirpath, f) for f in filenames
                if f.endswith('.txt') and f.startswith('Timing')
            ] for (dirpath, dirnames,
                   filenames) in os.walk(params.txt_path, followlinks=True)]
            files = [item for sublist in files_gen for item in sublist]
        else:
            files = os.listdir(params.txt_path)
            files = [
                linux_path(params.txt_path, k) for k in files
                if k and k.endswith('.txt')
            ]

        txt_proc_list_path = linux_path(params.txt_path, params.txt_proc_list)

        if os.path.isfile(txt_proc_list_path):
            processed_files = open(txt_proc_list_path, 'r').readlines()
            processed_files = [
                k.strip().split('\t')[1] for k in processed_files if k.strip()
            ]

            files = [k for k in files if k not in processed_files]

        files.sort(key=os.path.getmtime)
        n_files = len(files)

        if n_files > 0:
            _ = input('\nfound {} new files:\n{}\nPress any key to continue\n'.
                      format(n_files, files))
        else:
            _ = input('\nfound no new files. Press any key to exit\n')

        for file_id, file in enumerate(files[::-1]):
            if file_id > 0:
                _ = input('\nDone {} / {}. Press any key to continue\n'.format(
                    file_id, n_files))

            print('reading file {} / {}: {}'.format(file_id + 1, n_files,
                                                    file))

            # file = dst_file

            in_txt = open(file, 'r').read()
            out_txt = process(in_txt, verbose=0)
            print(out_txt)

            copy_to_clipboard(out_txt)
            time.sleep(0.5)

            out_txt_lines = [k for k in out_txt.split('\n') if k]

            n_out_txt_lines = len(out_txt_lines)

            # dst_file = file.replace('.txt', '.log')
            # shutil.move(file, dst_file)

            print('out_txt_lines: {}'.format(out_txt_lines))
            print('n_out_txt_lines: {}'.format(n_out_txt_lines))

            if n_out_txt_lines == 1:
                os.system("vscode {}".format(file))

            with open(txt_proc_list_path, 'r+') as f:
                content = f.read()
                f.seek(0, 0)

                timestamp_str = datetime.now().strftime(
                    "%y%m%d %H:%M:%S.%f")[:-4]

                txt = '{}\t{}\n'.format(timestamp_str, file)
                f.write(txt + content)

        return

    # time.sleep(1)
    try:
        orig_x, orig_y = win32api.GetCursorPos()
        print('GetCursorPos x: {}'.format(orig_x))
        print('GetCursorPos y: {}'.format(orig_y))

        win32gui.EnumWindows(foreach_window, None)

        # for i in range(len(titles)):
        #     print(titles[i])

        target_title = [
            k[1] for k in titles
            if all(title in k[1] for title in params.win_titles)
        ]
        # print('target_title: {}'.format(target_title))

        if not target_title:
            raise IOError('Window with win_titles: {} not found'.format(
                params.win_titles))

        target_title = target_title[0]

        target_handle = win32gui.FindWindow(None, target_title)
        rect = win32gui.GetWindowRect(target_handle)

        x = int((rect[0] + rect[2]) / 2)
        y = int((rect[1] + rect[3]) / 2)

        # active_handle = win32gui.GetForegroundWindow()
        # target_title = win32gui.GetWindowText(active_handle)

        print('target_title: {}'.format(target_title))
        print('rect: {}'.format(rect))
        print('x: {}'.format(x))
        print('y: {}'.format(y))

        try:
            app = application.Application().connect(title=target_title,
                                                    found_index=0)
        except BaseException as e:
            print('Failed to connect to app for window {}: {}'.format(
                target_title, e))
            exit(0)
        try:
            app_win = app.window(title=target_title)
        except BaseException as e:
            print('Failed to access app window for {}: {}'.format(
                target_title, e))
            exit(0)
        app_win.type_keys("^a")
        app_win.type_keys("^c")

        mouse.move(coords=(x, y))

        mouse.click(button='left', coords=(x, y))
        mouse.click(button='left', coords=(x, y))

        mouse.move(coords=(orig_x, orig_y))

    except BaseException as e:
        print('BaseException: {}'.format(e))

    in_txt = copy_from_clipboard()
    out_txt = process(in_txt)

    # with open(out_fname, 'w') as out_fid:
    #     out_fid.write(out_txt)

    copy_to_clipboard(out_txt, print_txt=1)
Esempio n. 20
0
 def move_mouse(self, x: int, y: int):
     mouse.move((x, y))
Esempio n. 21
0
 def moveMouse(self):
     mouse.move(coords=(random.randint(0,99), random.randint(0, 99)))
Esempio n. 22
0
 def mouse_move(x, y):
     mouse.move(coords=(x, y))
Esempio n. 23
0
            app = application.Application().connect(title=target_title,
                                                    found_index=0)
        except BaseException as e:
            print('Failed to connect to app for window {}: {}'.format(
                target_title, e))
            exit(0)
        try:
            app_win = app.window(title=target_title)
        except BaseException as e:
            print('Failed to access app window for {}: {}'.format(
                target_title, e))
            exit(0)
        app_win.type_keys("^a")
        app_win.type_keys("^c")

        mouse.move(coords=(x, y))

        mouse.click(button='left', coords=(x, y))
        mouse.click(button='left', coords=(x, y))

        mouse.move(coords=(orig_x, orig_y))

    except BaseException as e:
        print('BaseException: {}'.format(e))

    in_txt = Tk().clipboard_get()

    lines = in_txt.split('\n')
    lines = [line for line in lines if line.strip()]

    start_t = None
Esempio n. 24
0
    # for i in content:
    #     app.input(window_name,'',i)
    #     time.sleep(2)
    # app.close(window_name)

    app = windowAppopr(win32gui, win32api)
    tool_name = r'C:\十档行情\tdxw.exe'
    window_title = '通达信金融终端通赢版V7.47'
    window_class = '#32770 (Dialog)'
    processid = '00003FA0'
    window_name = '通达信金融终端通赢版V7.47'
    class_name = '#32770 (Dialog)'
    window_title_class = 'AfxWnd42'
    app.start(tool_name)
    app.connectForPath(window_name, tool_name)
    mouse.move([985, 420])
    mouse.click('left', [985, 420])  #左键在什么位置点击
    time.sleep(10)  #休息8秒,等等数据初始化加载
    # app.GetCursorPos()
    #点击A股,导出所有A股早盘数据
    mouse.click('left', [970, 990])
    ###点击选项数据导出,导出数据
    mouse.click('left', [1608, 11])
    mouse.click('left', [1655, 404])
    time.sleep(1)
    mouse.click('left', [827, 397])
    mouse.click('left', [1055, 547])
    time.sleep(1)
    mouse.click('left', [1110, 653])
    app.GetCursorPos()
    time.sleep(60)
	scroll:滚动鼠标

"""

from pywinauto import mouse

# 鼠标单击(默认左键)- 点击x轴坐标:214, y轴坐标:50
# mouse.click(coords=(214, 50))

# # 鼠标右键
# mouse.right_click(coords=(832, 507))

# # 鼠标双击
# mouse.double_click(button="left", coords=(553, 287))

# # 点击鼠标中键
# mouse.wheel_click(coords=(498, 228))

# # 按下鼠标
# mouse.press(coords=(34, 31))
# # 释放鼠标
# mouse.release(coords=(1000, 500))

# 滑动鼠标滚轮- wheel_dist:滚动次数,负数往下滚动,正数往上滚动
# mouse.scroll(coords=(850, 538), wheel_dist=2)

# 移动鼠标位置
mouse.move(coords=(0, 0))
for i in range(0, 1000, 50):
    mouse.move(coords=(i, i))
Esempio n. 26
0
def main():
    params = {
        'win_title': 'The Journal 8',
        'use_ahk': 1,
        'mode': 0,
        'wait_t': 10,
        'scp_dst': '',
        'key_root': '',
        'key_dir': '',
        'auth_root': '',
        'auth_dir': '',
        'auth_file': '',
        'auth_path': '',
        'dst_path': '.',
        'scp_path': '.',
        'scp_name': 'grs',
    }
    paramparse.process_dict(params)

    win_title = params['win_title']
    use_ahk = params['use_ahk']
    mode = params['mode']
    wait_t = params['wait_t']
    scp_dst = params['scp_dst']
    dst_path = params['dst_path']
    scp_path = params['scp_path']
    scp_name = params['scp_name']

    key_root = params['key_root']
    key_dir = params['key_dir']
    auth_root = params['auth_root']
    auth_dir = params['auth_dir']
    auth_file = params['auth_file']

    # Window.get_all_windows()

    if mode == -1 or mode == -2:
        pwd0 = auth_file
        port = None
    else:
        auth_path = linux_path(auth_root, auth_dir, auth_file)
        auth_data = open(auth_path, 'r').readlines()
        auth_data = [k.strip() for k in auth_data]

        dst_info = auth_data[0].split(' ')
        name00, name01, ecr0, key0 = dst_info[:4]

        if len(dst_info) > 4:
            port = dst_info[4]

        encryption_params = encryption.Params()
        encryption_params.mode = 1
        encryption_params.root_dir = key_root
        encryption_params.parent_dir = key_dir

        encryption_params.in_file = ecr0
        encryption_params.key_file = key0
        encryption_params.process()
        pwd0 = encryption.run(encryption_params)

    # Form1.SetFocus()
    default_fmy_key = '0'
    if mode == 0 or mode == -1:
        data_type = 'filename (from)'
        highlight_key = '2'
    elif mode == 1 or mode == -2:
        data_type = 'filename (to)'
        highlight_key = '3'
    elif mode == 2:
        data_type = 'log'
        highlight_key = '4'

    while True:
        k = input('\nEnter {}\n'.format(data_type))

        if not k:
            continue

        x, y = win32api.GetCursorPos()
        # EnumWindows(EnumWindowsProc(foreach_window), 0)
        if use_ahk:
            if mode == 0 or mode == -1:
                clip_txt = '{} from {}'.format(k, scp_name)
            elif mode == 1 or mode == -2:
                clip_txt = '{} to {}'.format(k, scp_name)

            try:
                import pyperclip

                pyperclip.copy(clip_txt)
                _ = pyperclip.paste()
            except BaseException as e:
                print('Copying to clipboard failed: {}'.format(e))

            os.system('paste_with_cat_1')
            run_scp(dst_path, pwd0, scp_dst, scp_path, k, mode, port)
            continue

        GetWindowText = ctypes.windll.user32.GetWindowTextW
        GetWindowTextLength = ctypes.windll.user32.GetWindowTextLengthW
        IsWindowVisible = ctypes.windll.user32.IsWindowVisible

        titles = []

        def foreach_window(hwnd, lParam):
            if IsWindowVisible(hwnd):
                length = GetWindowTextLength(hwnd)
                buff = ctypes.create_unicode_buffer(length + 1)
                GetWindowText(hwnd, buff, length + 1)
                titles.append((hwnd, buff.value))
            return True

        win32gui.EnumWindows(foreach_window, None)

        # for i in range(len(titles)):
        #     print(titles[i])

        target_title = [k[1] for k in titles if k[1].startswith(win_title)]
        # print('target_title: {}'.format(target_title))

        if not target_title:
            print('Window with win_title: {} not found'.format(win_title))
            run_scp(dst_path, pwd0, scp_dst, scp_path, k, mode, port)
            continue

        target_title = target_title[0]
        # print('target_title: {}'.format(target_title))

        try:
            app = application.Application().connect(title=target_title,
                                                    found_index=0)
        except BaseException as e:
            print('Failed to connect to app for window {}: {}'.format(
                target_title, e))
            run_scp(dst_path, pwd0, scp_dst, scp_path, k, mode, port)
            continue
        try:
            app_win = app.window(title=target_title)
        except BaseException as e:
            print('Failed to access app window for {}: {}'.format(
                target_title, e))
            run_scp(dst_path, pwd0, scp_dst, scp_path, k, mode, port)
            continue

        try:
            # if mode == 2:
            #     enable_highlight = k.strip()
            #     app_win.type_keys("^t~")
            #     app_win.type_keys("^v")
            #     app_win.type_keys("^+a")
            #     if enable_highlight:
            #         app_win.type_keys("^+%a")
            #         # time.sleep(1)
            #         app_win.type_keys("^+z")
            #         app_win.type_keys("{RIGHT}{VK_SPACE}~")
            #     else:
            #         app_win.type_keys("{VK_SPACE}~")
            #
            #     app_win.type_keys("^s")
            #     continue

            app_win.type_keys("^t{VK_SPACE}::{VK_SPACE}1")
            app_win.type_keys("^+a")
            app_win.type_keys("^2")
            # app_win.type_keys("^+1")
            app_win.type_keys("{RIGHT}{LEFT}~")
            app_win.type_keys("^v")
            if mode == 1:
                app_win.type_keys("{LEFT}{RIGHT}{VK_SPACE}to{VK_SPACE}%s" %
                                  scp_name)
            # app_win.type_keys("^+a")
            # app_win.type_keys("^{}".format(highlight_key))
            # app_win.type_keys("{LEFT}{RIGHT}~")
            # app_win.type_keys("^{}".format(default_fmy_key))
            app_win.type_keys("~")
            app_win.type_keys("^s")

            mouse.move(coords=(x, y))
        except BaseException as e:
            print('Failed to type entry in app : {}'.format(e))
            pass

        run_scp(dst_path, pwd0, scp_dst, scp_path, k, mode, port)