Exemple #1
0
    def show(self):
        """
        Show overlay UI

        This searches for elite dangerous game window and resizes overlay window to fully cover ED window.
        """
        if not self.ed_window_handler:
            handler = get_ed_window_handler()
            if not handler:
                logger.warning('ED window not found')
                return
            self.ed_window_handler = handler

        focus_handler = win32gui.GetFocus()
        if focus_handler not in (self.ed_window_handler, 0):
            return

        rect = get_ed_window_rect(self.ed_window_handler)
        logger.debug(f'ED window rect is {rect}')
        self.setFixedSize(rect.h, rect.w)
        self.move(rect.x, rect.y)
        # self.setFixedSize(800, 600)
        # self.move(400, 400)
        # win32gui.SetFocus(self.ed_window_handler)
        super(GameOverlayWindow, self).show()
Exemple #2
0
 def HasFocus(self):
     """
     Get the current window focus state.
     :return: True if in focus else False
     :rtype: bool
     """
     return self.hwnd == win32gui.GetFocus()
Exemple #3
0
 def GetFocus(cls):
     curtid = win32api.GetCurrentThreadId()
     whd = win32gui.GetForegroundWindow()
     (tid, pid) = win32process.GetWindowThreadProcessId(whd)
     win32process.AttachThreadInput(curtid, tid, True)
     focus_whd = win32gui.GetFocus()
     win32process.AttachThreadInput(curtid, tid, False)
     return focus_whd
Exemple #4
0
def CaptureScreen():
    HWND = win32gui.GetFocus()
    rect = win32gui.GetWindowRect(HWND)
    x = rect[0]
    x1 = x + cv.winfo_width()
    y = rect[1]
    y1 = y + cv.winfo_height()
    im = ImageGrab.grab((x, y, x1, y1))
    im.save("second.jpeg", 'jpeg')
Exemple #5
0
    def get_image(self):
        HWND = win32gui.GetFocus()  #获取当前窗口句柄
        rect = win32gui.GetWindowRect(HWND)  #获取当前窗口坐标
        img = ImageGrab.grab(rect)  #截取目标图像
        #img = img.resize((100,100))
        img = img.resize((50, 50), Image.ANTIALIAS)
        #img.save(str(self.fn) + ".jpeg",'jpeg') #前面一个参数是保存路径,后面一个参数是保存格式
        #self.fn = self.fn + 1
        img = img.convert('L')
        img = np.array(img)
        img = (img - 128) / 128 - 1

        return img.reshape(50, 50)
Exemple #6
0
def press_code_on_ths(hwnd_ths, code='002531'):
    win32gui.PostMessage(hwnd_ths, win32con.WM_KEYDOWN, ord('6') & 0xFF, 0)
    win32gui.PostMessage(hwnd_ths, win32con.WM_KEYUP, ord('6') & 0xFF, 0)
    time.sleep(0.3)
    win32gui.SetForegroundWindow(hwnd_ths)
    self_thread_id = win32api.GetCurrentThreadId()
    fore_thread_id = win32process.GetWindowThreadProcessId(hwnd_ths)
    win32process.AttachThreadInput(fore_thread_id[0], self_thread_id, True)
    obj_wnd = win32gui.GetFocus()
    win32gui.SendMessage(obj_wnd, win32con.WM_SETTEXT, 0, code)
    win32gui.PostMessage(obj_wnd, win32con.WM_KEYDOWN, win32con.VK_RETURN, 0)
    win32gui.PostMessage(obj_wnd, win32con.WM_KEYUP, win32con.VK_RETURN, 0)
    win32process.AttachThreadInput(fore_thread_id[0], self_thread_id, False)
    return True
Exemple #7
0
        # print('cann\'t find 同花顺')
        break
    if win32gui.IsWindowVisible(hwndChild):
        win_text = win32gui.GetWindowText(hwndChild)
        # print(win_text[0:3])
        if win_text[0:3] == '同花顺':
            break

print(hwndChild)
if hwndChild != 0:
    print(
        win32gui.PostMessage(hwndChild, win32con.WM_KEYDOWN,
                             ord('6') & 0xFF, 0))
    print(
        win32gui.PostMessage(hwndChild, win32con.WM_KEYUP,
                             ord('6') & 0xFF, 0))
    time.sleep(0.3)
    win32gui.SetForegroundWindow(hwndChild)
    self_thread_id = win32api.GetCurrentThreadId()
    fore_thread_id = win32process.GetWindowThreadProcessId(hwndChild)
    print(self_thread_id, fore_thread_id)
    print(
        win32process.AttachThreadInput(fore_thread_id[0], self_thread_id,
                                       True))
    objwnd = win32gui.GetFocus()
    str = '600030'
    win32gui.SendMessage(objwnd, win32con.WM_SETTEXT, 0, str)
    win32gui.PostMessage(objwnd, win32con.WM_KEYDOWN, win32con.VK_RETURN, 0)
    win32gui.PostMessage(objwnd, win32con.WM_KEYUP, win32con.VK_RETURN, 0)
    win32process.AttachThreadInput(fore_thread_id[0], self_thread_id, False)
    def item_click_response(self, item):
        if self.combo_box_item_click_response.currentText() == '编辑':
            if item.parent():
                group_list = [gp for gp in self.get_database_dict()]
                old_content = (item.parent().text(0), item.text(0),
                               item.text(1))
                dialog = EditContentDialog(self, group_list, old_content)
                return_signal = dialog.exec_()
                if return_signal == QDialog.Accepted:
                    if old_content != dialog.add_content:
                        old_group, old_key, old_content = old_content
                        group, key, content = dialog.add_content
                        self.db_cursor.execute(
                            '''UPDATE CLIPBOARD SET CONTENT_GROUP = \'%s\', 
                            KEY = \'%s\', CONTENT = \'%s\' 
                            WHERE CONTENT_GROUP = \'%s\' AND 
                            KEY = \'%s\' AND 
                            CONTENT = \'%s\'''' %
                            (group, key, content, old_group, old_key,
                             old_content))
                        self.db_conn.commit()
                        self.display_clip_board_database()
        elif self.combo_box_item_click_response.currentText() == '复制':
            if item.parent():
                self.clip_board.setText(item.text(1))
        elif self.combo_box_item_click_response.currentText() == '复制并粘贴':
            if item.parent():
                self.clip_board.setText(item.text(1))
                focus_win_hwnd = xx = win32gui.GetFocus()
                hwnd_title = dict()

                def get_all_window(hwnd, mouse):

                    if win32gui.IsWindow(hwnd) and win32gui.IsWindowEnabled(hwnd) and\
                            win32gui.IsWindowVisible(hwnd):
                        hwnd_title.update({hwnd: win32gui.GetWindowText(hwnd)})

                win32gui.EnumWindows(get_all_window, 1)
                if hwnd_title:
                    hwnd_list = [h for h, t in hwnd_title.items()]
                    index = hwnd_list.index(focus_win_hwnd)
                    if self.is_top:
                        if index < len(hwnd_list) - 2:
                            focus_win_hwnd = hwnd_list[index + 2]
                            win32gui.SetForegroundWindow(focus_win_hwnd)
                            win32api.keybd_event(17, 0, 0, 0)
                            win32api.keybd_event(86, 0, 0, 0)
                            win32api.keybd_event(86, 0,
                                                 win32con.KEYEVENTF_KEYUP, 0)
                            win32api.keybd_event(17, 0,
                                                 win32con.KEYEVENTF_KEYUP, 0)
                            win32api.keybd_event(13, 0, 0, 0)
                            win32api.keybd_event(13, 0,
                                                 win32con.KEYEVENTF_KEYUP, 0)
                    else:
                        if index < len(hwnd_list) - 1:
                            focus_win_hwnd = hwnd_list[index + 1]
                            win32gui.SetForegroundWindow(focus_win_hwnd)
                            win32api.keybd_event(17, 0, 0, 0)
                            win32api.keybd_event(86, 0, 0, 0)
                            win32api.keybd_event(86, 0,
                                                 win32con.KEYEVENTF_KEYUP, 0)
                            win32api.keybd_event(17, 0,
                                                 win32con.KEYEVENTF_KEYUP, 0)
                            win32api.keybd_event(13, 0, 0, 0)
                            win32api.keybd_event(13, 0,
                                                 win32con.KEYEVENTF_KEYUP, 0)
        else:
            pass
Exemple #9
0
 def get_focus_window():
     """Within current thread
 @return  HWND or ?
 """
     return win32gui.GetFocus()
Exemple #10
0
def main(workbook, workspace="My workspace"):

    time.sleep(2)
    WORKBOOK = workbook
    WORKSPACE = workspace
    INIT_WAIT = 30000
    REFRESH_TIMEOUT = 15

    print("----- Fecha Power BI em execução")
    PROCNAME = "PBIDesktop.exe"
    try:
        app = Application(backend='uia').connect(path=PROCNAME)
        win = app.window(title_re='.*Power BI Desktop')
        win.close()
        time.sleep(2)
        print('Power BI foi fechado!')
    except:
        pass

    filtrar_titulo = workbook.split('.')[0].split('\\')[-1]
    titulo = f'{filtrar_titulo} - Power BI Desktop'

    print("----- Iniciando Power BI")
    try:
        os.system('start "" "' + workbook + '"')
    except Exception:
        print(Exception)
    time.sleep(25)

    PROCNAME = "PBIDesktop.exe"

    # Connect pywinauto
    print("----- Encontrando o Power BI")
    try:
        app = Application(backend='uia').connect(path=PROCNAME)
        win = app.window(title_re='.*Power BI Desktop')
        top_windows = Desktop(backend="uia").windows()
        win.wait("enabled", timeout=25)

        for w in top_windows:
            pbi = f'{w.window_text()}'
            if pbi == titulo:
                a: str = f'{pbi}'
                hwnd = win32gui.FindWindow(None, (a))
                win32gui.MoveWindow(hwnd, 30, 30, 900, 900, True)
                win32gui.GetFocus()
                win.wait("enabled", timeout=10)
    except:
        sys.exit(1)

    time.sleep(5)

    print('----- Atualizando')

    win.click_input(coords=(450, 100))
    time.sleep(40)

    print("----- Salvando")
    try:
        win.click_input(coords=(17, 13))
        win.click_input(coords=(17, 13))
        win.click_input(coords=(17, 13))
        win.click_input(coords=(17, 13))
    except Exception as e:
        print(e)

    time.sleep(5)
    win.wait("enabled", timeout=10)

    print('----- Publicar na Web')
    win.click_input(coords=(780, 100))
    time.sleep(3)
    WORKSPACE = "Meu workspace"

    publish_dialog = win.child_window(auto_id="KoPublishToGroupDialog")
    publish_dialog.workspaceDataItem.click_input()
    publish_dialog.workspaceDataItem.child_window().click_input()
    # print_control_identifiers()
    publish_dialog.Select.click()
    try:
        win.Replace.wait('visible', timeout=10)
    except Exception:
        pass
    if win.Replace.exists():
        win.Replace.click_input()
    time.sleep(5)
    win["Got it"].wait('visible', timeout=30000)
    win["Got it"].click_input()

    PROCNAME = "PBIDesktop.exe"
    try:
        app = Application(backend='uia').connect(path=PROCNAME)
        win = app.window(title_re='.*Power BI Desktop')
        win.close()
        time.sleep(2)
        print('----- Power BI foi publicado e fechado!')
    except:
        pass
Exemple #11
0
def GetFocus():
    """
    功能确定当前焦点位于哪个控件上
    :return:
    """
    return win32gui.GetFocus()
import win32gui
import win32gui_struct
import win32con
from win32com.shell import shell, shellcon
import time
import pywintypes

while(1):
    pt = win32gui.GetCursorPos()
    hwnd = win32gui.WindowFromPoint(pt)
    w0, h0, w1, h1 = win32gui.GetWindowRect(hwnd)
    focus = win32gui.GetFocus()
    #win32gui.DrawFocusRect( hwnd, (w0, h0, w1, h1))
    #win32gui.DrawEdge( hwnd, (w0, h0, w1, h1), win32con.BDR_INNER, win32con.BF_ADJUST)
    print( "my point:",w0, h0, w1, h1 )
    print( "client point:", win32gui.GetClientRect(hwnd))
    parent = win32gui.GetParent( hwnd )
    active = win32gui.GetActiveWindow()
    print("window placement: ", win32gui.GetWindowPlacement(hwnd))
    childwindow = win32gui.ChildWindowFromPoint(hwnd, win32gui.GetCursorPos())
    print( "capture : ", win32gui.GetCapture())
    window = win32gui.GetWindow(hwnd, 1)
    win32gui.SendMessage( hwnd, 1, None, None)
    desktop = win32gui.GetDesktopWindow()
    menu = win32gui.GetMenu(hwnd)
    cursorinfo = win32gui.GetCursorInfo()
    foreground = win32gui.GetForegroundWindow()
    hdc = win32gui.GetDC(hwnd)
    #win32gui.PolylineTo(hdc, ((w0, h0), (w1, h0), (w1, h1), (w0, h1), (w0,h0)))
    obj = win32gui.GetCurrentObject(hdc, win32con.OBJ_BITMAP)
    stockobj = win32gui.GetStockObject(obj)
Exemple #13
0
def CaptureScreen():
    HWND = win32gui.GetFocus()  #获取当前窗口句柄
    rect = win32gui.GetWindowRect(HWND)  #获取当前窗口坐标
    im = ImageGrab.grab(rect)  #截取目标图像
    im.save("second.jpeg", 'jpeg')  #前面一个参数是保存路径,后面一个参数是保存格式