Esempio n. 1
0
        def attempt_focus():
            for win in Window.get_all_windows():
                w = win
                found_match = True
                if title != None:
                    found_match = title in w.title
                if found_match and executable != None:
                    found_match = executable in w.executable
                if found_match:
                    try:
                        # this is still broken
                        win32gui.SetWindowPos(
                            w.handle, win32con.HWND_NOTOPMOST, 0, 0, 0, 0,
                            win32con.SWP_NOMOVE + win32con.SWP_NOSIZE)
                        win32gui.SetWindowPos(
                            w.handle, win32con.HWND_TOPMOST, 0, 0, 0, 0,
                            win32con.SWP_NOMOVE + win32con.SWP_NOSIZE)
                        win32gui.SetWindowPos(
                            w.handle, win32con.HWND_NOTOPMOST, 0, 0, 0, 0,
                            win32con.SWP_SHOWWINDOW + win32con.SWP_NOMOVE +
                            win32con.SWP_NOSIZE)
                        Key("alt").execute()
                        time.sleep(0.5)
                        win32gui.SetForegroundWindow(w.handle)
                        w.set_foreground()
                    except Exception:
                        utilities.report("Unable to set focus:\ntitle: " +
                                         w.title + "\nexe: " + w.executable)
                    break

            # do not assume that it worked
            success = SuperFocusWindow.focus_was_success(title, executable)
            if not success:
                if title != None:
                    print "title failure: ", title, w.title
                if executable != None:
                    print "executable failure: ", executable, w.executable, executable in w.executable
            return success
def send_wechat(msg):

    setImage(msg)
    wechat = win32gui.FindWindow('ChatWnd', u"购物福利券群")
    left, top, right, bottom = win32gui.GetWindowRect(wechat)
    print(left, top, right, bottom)
    pos = win32api.GetCursorPos()
    win32api.SetCursorPos((left + 150, bottom - 100))
    win32gui.SetForegroundWindow(wechat)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0)
    win32api.SetCursorPos((int(pos[0]), int(pos[1])))
    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)
    win32gui.SetWindowPos(wechat, win32con.HWND_BOTTOM, 0, 0, 0, 0,
                          win32con.SWP_NOSIZE | win32con.SWP_NOMOVE)

    wechat2 = win32gui.FindWindow('ChatWnd', u"淘宝优惠券")
    left, top, right, bottom = win32gui.GetWindowRect(wechat)
    print(left, top, right, bottom)
    pos = win32api.GetCursorPos()
    win32api.SetCursorPos((left + 150, bottom - 100))
    win32gui.SetForegroundWindow(wechat)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0)
    win32api.SetCursorPos((int(pos[0]), int(pos[1])))
    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)
    win32gui.SetWindowPos(wechat, win32con.HWND_BOTTOM, 0, 0, 0, 0,
                          win32con.SWP_NOSIZE | win32con.SWP_NOMOVE)
Esempio n. 3
0
 def getWindow_Img_new(self,Emu_Index):
     self.Hwnd = int(self.Get_Self_Hawd(Emu_Index))
 
 # 將 hwnd 換成 WindowLong
     s = win32gui.GetWindowLong(self.Hwnd,win32con.GWL_EXSTYLE)
     win32gui.SetWindowLong(self.Hwnd, win32con.GWL_EXSTYLE, s|win32con.WS_EX_LAYERED)
 # 判斷視窗是否最小化
     show = win32gui.IsIconic(self.Hwnd)
 # 將視窗圖層屬性改變成透明    
 # 還原視窗並拉到最前方
 # 取消最大小化動畫
 # 取得視窗寬高
     if show == 1: 
         win32gui.SystemParametersInfo(win32con.SPI_SETANIMATION, 0)
         win32gui.SetLayeredWindowAttributes(self.Hwnd, 0, 0, win32con.LWA_ALPHA)
         win32gui.ShowWindow(self.Hwnd, win32con.SW_RESTORE)    
         x, y, width, height = self.getWindow_W_H(self.Hwnd)        
 # 創造輸出圖層
     hwindc = win32gui.GetWindowDC(self.Hwnd)
     srcdc = win32ui.CreateDCFromHandle(hwindc)
     memdc = srcdc.CreateCompatibleDC()
     bmp = win32ui.CreateBitmap()
 # 取得視窗寬高
     x, y, width, height = self.getWindow_W_H(self.Hwnd)
 # 如果視窗最小化,則移到Z軸最下方
     if show == 1: win32gui.SetWindowPos(self.Hwnd, win32con.HWND_BOTTOM, x, y, width, height, win32con.SWP_NOACTIVATE)
 # 複製目標圖層,貼上到 bmp
     bmp.CreateCompatibleBitmap(srcdc, width, height)
     memdc.SelectObject(bmp)
     memdc.BitBlt((0 , 0), (width, height), srcdc, (8, 3), win32con.SRCCOPY)
 # 將 bitmap 轉換成 np
     signedIntsArray = bmp.GetBitmapBits(True)
     img = np.fromstring(signedIntsArray, dtype='uint8')
     img.shape = (height, width, 4) #png,具有透明度的
 
 # 釋放device content
     srcdc.DeleteDC()
     memdc.DeleteDC()
     win32gui.ReleaseDC(self.Hwnd, hwindc)
     win32gui.DeleteObject(bmp.GetHandle())
 # 還原目標屬性
     if show == 1 :
         win32gui.SetLayeredWindowAttributes(self.Hwnd, 0, 255, win32con.LWA_ALPHA)
         win32gui.SystemParametersInfo(win32con.SPI_SETANIMATION, 1)
 # 回傳圖片
     #src_img = img
     #src_img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
     #src_img = cv2.imwrite('test1.jpg',img)
     self.ScreenHot = img
     return img
Esempio n. 4
0
def FindWindow(chatroom):
    win = win32gui.FindWindow(None, chatroom)
    print("找到群聊窗口:%x" % win)
    if win != 0:
        win32gui.ShowWindow(win, win32con.SW_SHOWMINIMIZED)
        win32gui.ShowWindow(win, win32con.SW_SHOWNORMAL)
        win32gui.ShowWindow(win, win32con.SW_SHOW)
        win32gui.SetWindowPos(win, win32con.HWND_TOPMOST, 100, 100, 300, 300,
                              win32con.SWP_SHOWWINDOW)
        win32gui.SetForegroundWindow(win)  # 获取控制
        time.sleep(1)
    else:
        print('请注意:找不到【%s】这个人(或群),请激活窗口!' % chatroom)
        exit()
Esempio n. 5
0
def main():
    time.sleep(3)
    ffplay = win32gui.FindWindow(None, "pynamic_player")
    progman = win32gui.FindWindow("Progman", "Program Manager")
    win32gui.SendMessageTimeout(progman, 0x052C, 0, 0, win32con.SMTO_NORMAL,
                                1000)
    time.sleep(0.1)
    hwnd = win32gui.GetWindow(progman, win32con.GW_HWNDPREV)
    wkwname = win32gui.GetClassName(hwnd)
    print(wkwname)
    if wkwname == "WorkerW":
        win32gui.SetParent(ffplay, hwnd)
        win32gui.SetWindowPos(ffplay, win32con.HWND_BOTTOM, 0, 0, w, h,
                              0 | win32con.SWP_NOZORDER)
Esempio n. 6
0
def eig():

    un.leftOneClick(224, 32)
    un.leftOneClick(290, 157)
    un.leftOneClick(618, 252)
    procHandle = win32gui.FindWindow(None, "Eigenvector Centrality")
    win32gui.SetWindowPos(procHandle, win32con.HWND_TOPMOST, 200, 200, 0, 0,
                          win32con.SWP_NOSIZE)
    time.sleep(1)
    un.leftOneClick(773, 300)
    #un.leftOneClick(236, 188)
    un.leftOneClick(238, 162)
    un.key_Ok()
    un.key_Ok()
Esempio n. 7
0
    def OnInitDialog(self, hwnd, msg, wparam, lparam):
        self.hwnd = hwnd

        desktop = win32gui.GetDesktopWindow()
        dt_l, dt_t, dt_r, dt_b = win32gui.GetWindowRect(desktop)
        centre_x, centre_y = win32gui.ClientToScreen( desktop, ( (dt_r-dt_l)/2, (dt_b-dt_t)/2) )

        bmCtrl = win32gui.GetDlgItem(self.hwnd, IDC_BITMAP)
        win32gui.SendMessage(bmCtrl, win32con.STM_SETIMAGE, win32con.IMAGE_BITMAP, self.hSplash)

        win32gui.SetWindowPos(self.hwnd, win32con.HWND_TOPMOST, 
                              centre_x-(self.bmWidth/2), centre_y-(self.bmHeight/2), 
                              self.bmWidth, self.bmHeight, win32con.SWP_HIDEWINDOW)
        win32gui.SetForegroundWindow(self.hwnd)
Esempio n. 8
0
def set_not_always_on_top(*args, title=''):
    '''
    Sets the HWND_NOTOPMOST flag for the current Kivy Window.
    '''

    hwnd = find_hwnd(title)

    rect = win32gui.GetWindowRect(hwnd)
    x = rect[0]
    y = rect[1]
    w = rect[2] - x
    h = rect[3] - y

    win32gui.SetWindowPos(hwnd, win32con.HWND_NOTOPMOST, x, y, w, h, 0)
Esempio n. 9
0
def set_client_size(h_wnd: int, width: int, height: int):
    init()
    left, top, right, bottom = win32gui.GetWindowRect(h_wnd)
    _, _, w, h = win32gui.GetClientRect(h_wnd)
    LOGGER.info("width=%s height=%s", w, h)
    if h == height and w == width:
        LOGGER.info("already in wanted size")
        return
    borderWidth = right - left - w
    borderHeight = bottom - top - h
    win32gui.SetWindowPos(h_wnd, 0, left, top, width + borderWidth,
                          height + borderHeight, 0)
    set_client_size(h_wnd, width, height)  # repeat until exact match
    return
Esempio n. 10
0
def run_CrystalDiskInfo(target="T"):

    tool = "CrystalDiskInfo 7.6.0 "
    tool_path = r'start "aa" "C:\Program Files (x86)\CrystalDiskInfo\DiskInfo64.exe'
    os.system(tool_path)
    time.sleep(5)
    hwnd = win32gui.FindWindow(None, tool)  #找到tool 所在的窗口
    win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, 383, 140, 0, 0,
                          win32con.SWP_NOSIZE)  #设置窗口为焦点
    assert win32gui.GetWindowText(hwnd) == tool, "run tool name wrong!"

    filename = "{}.bmp".format(tool)
    screenPrt.ScreenPrintWin().save_bitmap(bmp_filename=filename)
    print("run {} finished!".format(tool))
Esempio n. 11
0
    def _findForm(self, type, tag, autoCreate=False, autoChange=False):
        _tag = self._getTag(type, tag)
        winFrom = self.manager.get(_tag, None)
        if (winFrom == None):
            if (autoCreate):
                self._initForm(type, tag, randomXY=True)
                winFrom = self.manager.get(_tag, None)
            elif (autoChange):
                # 去除空闲窗体记录
                for x in list(self.manager.keys()):
                    frm = self.manager[x]
                    if (frm.isUsed == False):
                        self.manager.pop(x)

                # 提取空闲窗体备用
                for x in self.managerTemp:
                    if (x.isUsed == False and x.type == type):
                        winFrom = x
                        winFrom.tag = _tag
                        self.manager[_tag] = winFrom

                        #提取配置信息,并还原
                        pSet = self.setWinForm.getSet("", "", winFrom.tag)
                        if (pSet != None):
                            if (pSet.formRePos):
                                pos = pSet.formPos
                                hwndForm = win32gui.FindWindow(
                                    "Qt5QWindowToolSaveBits", winFrom.name)
                                if (hwndForm > 0):
                                    #移动窗体,还原记忆位置,SetWindowPos方法单次不一定成功,多次校检操作
                                    myDebug.Debug(F"还原窗体({winFrom.name})位置",
                                                  pos[0], ",", pos[1])
                                    while (winFrom.x != pos[0]
                                           and winFrom.y != pos[1]):
                                        winFrom._initForm(
                                            pos[0], pos[1], pos[2], pos[3],
                                            False)
                                        win32gui.SetWindowPos(
                                            hwndForm,
                                            win32con.HWND_TOPMOST,
                                            pos[0],  # x位置
                                            pos[1],  # y位置
                                            pos[2],  # 宽
                                            pos[3],  # 高
                                            win32con.SWP_SHOWWINDOW)
                                        #myDebug.Debug(winFrom.x, ",", winFrom.y)
                                winFrom.savePos = pSet.formRePos
                        break
        return winFrom
Esempio n. 12
0
    def SetWindowPos(me, p, rect, i):
        if user32:

            return (win32gui.SetWindowPos(me.h, p, rect[0], rect[1], rect[2],
                                          rect[3], i))

        if X:
            ec = Xlib.error.CatchError()
            x = rect[0]
            y = rect[1]
            w = rect[2] - rect[0]
            h = rect[3] - rect[1]
            if (x < 0) or (y < 0):
                alt_k = xdisplay.keysym_to_keycode(Xlib.XK.XK_Alt_R)

                me.h.configure(x=0,
                               y=0,
                               width=max(60, w),
                               height=max(60, h),
                               onerror=ec)
                xdisplay.sync()

                do_mouse_event(
                    'm', 50,
                    50)  # !!!! get the current position and restore it

                xdisplay.xtest_fake_input(Xlib.X.KeyPress, alt_k)
                xdisplay.flush()

                do_mouse_event('d', 50, 50)

                do_mouse_event(
                    'm', 10, 10
                )  # moves the window off-screen so it can be moved other places off screen

                do_mouse_event('u', 10, 10)

                xdisplay.xtest_fake_input(Xlib.X.KeyRelease, alt_k)
                xdisplay.flush()

            me.h.configure(x=x, y=y, width=w, height=h, onerror=ec)
            xdisplay.sync()
            if not ec.get_error():

                return (True)

            pass

        return (False)
Esempio n. 13
0
def SetWindowPos(hwnd, flag=0):
    """
    置顶窗口
    pos:
        HWND_BOTTOM:将窗口置于Z序的底部。如果参数hWnd标识了一个顶层窗口,则窗口失去顶级位置,并且被置在其他窗口的底部。
        HWND_DOTTOPMOST:将窗口置于所有非顶层窗口之上(即在所有顶层窗口之后)。如果窗口已经是非顶层窗口则该标志不起作用。
        HWND_TOP:将窗口置于Z序的顶部。
        HWND_TOPMOST:将窗口置于所有非顶层窗口之上。即使窗口未被激活窗口也将保持顶级位置。
    Flags:窗口尺寸和定位的标志。该参数可以是下列值的组合:
        SWP_ASYNCWINDOWPOS:如果调用进程不拥有窗口,系统会向拥有窗口的线程发出需求。这就防止调用线程在其他线程处理需求的时候发生死锁。
        SWP_DEFERERASE:防止产生WM_SYNCPAINT消息。
        SWP_DRAWFRAME:在窗口周围画一个边框(定义在窗口类描述中)。
        SWP_FRAMECHANGED:给窗口发送WM_NCCALCSIZE消息,即使窗口尺寸没有改变也会发送该消息。如果未指定这个标志,只有在改变了窗口尺寸时才发送WM_NCCALCSIZE。
        SWP_HIDEWINDOW;隐藏窗口。
        SWP_NOACTIVATE:不激活窗口。如果未设置标志,则窗口被激活,并被设置到其他最高级窗口或非最高级组的顶部(根据参数hWndlnsertAfter设置)。
        SWP_NOCOPYBITS:清除客户区的所有内容。如果未设置该标志,客户区的有效内容被保存并且在窗口尺寸更新和重定位后拷贝回客户区。
        SWP_NOMOVE:维持当前位置(忽略X和Y参数)。
        SWP_NOOWNERZORDER:不改变z序中的所有者窗口的位置。
        SWP_NOREDRAW: 不重画改变的内容。如果设置了这个标志,则不发生任何重画动作。适用于客户区和非客户区(包括标题栏和滚动条)和任何由于窗回移动而露出的父窗口的所有部分。如果设置了这个标志,应用程序必须明确地使窗口无效并区重画窗口的任何部分和父窗口需要重画的部分。
        SWP_NOREPOSITION;与SWP_NOOWNERZORDER标志相同。
        SWP_NOSENDCHANGING:防止窗口接收WM_WINDOWPOSCHANGING消息。
        SWP_NOSIZE:维持当前尺寸(忽略cx和Cy参数)。
        SWP_NOZORDER:维持当前Z序(忽略hWndlnsertAfter参数)。
        SWP_SHOWWINDOW:显示窗口
    :param hwnd:
    :param x:
    :param y:
    :param w:
    :param h:
    :param pos:
    :param flag:
    :return:
    """
    RestoreWindow(hwnd)
    SetForegroundWindow(hwnd)
    # 置顶
    flags = (win32con.SWP_NOSIZE
             | win32con.SWP_NOMOVE
             | win32con.SWP_SHOWWINDOW
             | win32con.SWP_ASYNCWINDOWPOS)
    if flag == 0:
        pos = win32con.HWND_TOPMOST
    # 取消置顶
    elif flag == 1:
        pos = win32con.HWND_NOTOPMOST
    # 窗口最前
    elif flag == 2:
        pos = win32con.HWND_TOP
    return win32gui.SetWindowPos(hwnd, pos, 0, 0, 0, 0, flags)
Esempio n. 14
0
def set_top(hwnd):
    win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, x, y, w, h,
                          win32con.SWP_NOACTIVATE)
    logging.log(logging.DEBUG,
                "SetWindowPos to HWND_TOPMOST and SWP_NOACTIVATE")

    style = win32api.GetWindowLong(hwnd, win32con.GWL_EXSTYLE)
    logging.log(logging.DEBUG, "Got style %X before" % style)

    style = style | win32con.WS_EX_LAYERED | win32con.WS_EX_TRANSPARENT | win32con.WS_EX_TOPMOST
    win32api.SetWindowLong(hwnd, win32con.GWL_EXSTYLE, style)
    logging.log(logging.DEBUG, "Setting style %X" % style)

    style = win32api.GetWindowLong(hwnd, win32con.GWL_EXSTYLE)
    logging.log(logging.DEBUG, "Got style %X after" % style)
Esempio n. 15
0
    def show(self):
        # Show main window
        win32gui.SetWindowPos(self.hwnd, win32con.HWND_TOP, self.pos_x,
                              self.pos_y, self.width, self.height,
                              win32con.SWP_SHOWWINDOW)
        win32gui.ShowWindow(self.hwnd, win32con.SW_SHOWNORMAL)
        win32gui.UpdateWindow(self.hwnd)

        # Show AtlAx window
        win32gui.ShowWindow(self.atlhwnd, win32con.SW_SHOW)
        win32gui.UpdateWindow(self.atlhwnd)
        win32gui.SetFocus(self.atlhwnd)

        # Pump messages
        win32gui.PumpMessages()
Esempio n. 16
0
    def _action(self):
        if h := win32gui.FindWindow(0, self.window_title):
            win32gui.ShowWindow(h, SW_SHOWMINIMIZED)
            win32gui.ShowWindow(h, SW_SHOWNORMAL)
            win32gui.ShowWindow(h, SW_SHOW)
            win32gui.SetForegroundWindow(h)
            win32gui.SetWindowPos(h, HWND_TOPMOST, 300, 100, 300, 300, SWP_SHOWWINDOW)

            while self.num > 0:
                # win32gui.SetWindowPos(h, HWND_TOPMOST, 100, 100, 300, 300, SWP_SHOWWINDOW)
                win32api.SendMessage(h, WM_PASTE, 0, 0)
                time.sleep(self.sleep)
                win32api.SendMessage(h, WM_KEYDOWN, VK_RETURN, 0)
                win32api.SendMessage(h, WM_KEYUP, VK_RETURN, 0)
                self.num -= 1
Esempio n. 17
0
    def always_on_top(self, _):
        # find this window
        def windowEnumHandler(hwnd, top_windows):
            # print((hwnd, win32gui.GetWindowText(hwnd)))
            top_windows.append((hwnd, win32gui.GetWindowText(hwnd)))

        top_windows = []
        win32gui.EnumWindows(windowEnumHandler, top_windows)
        for window in top_windows:

            if 'AlwaysOnTop'.lower() == window[1].lower():
                rect = win32gui.GetWindowRect(window[0])
                win32gui.SetWindowPos(window[0], win32con.HWND_TOPMOST,
                                      rect[0], rect[1], rect[2], rect[3], 0)
                break
Esempio n. 18
0
    def set_window_pos(cls, hwnd, x, y, width, height):
        """
        设置窗口的位置和大小
        Args:
            hwnd (int): 指定窗口句柄
            x (int): 窗口左上角x坐标
             (int): 窗口左上角y坐标
            width (int): 窗口宽度
            height (int): 窗宽高度

        Returns:

        """
        win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, x, y, width, height,
                              win32con.SWP_SHOWWINDOW)
Esempio n. 19
0
def  drawcircle(classname,title):
    wangwang=win32gui.FindWindow(classname,title)
    SE = 0.0
    while SE - 3.1415926535 * 2 < 0.000001:
        SE += 0.1
        newx = int(400 + 400 * math.cos(SE))
        newy = int(400 + 400 * math.sin(SE))
        win32gui.SetWindowPos(wangwang,  # 操作记事本
                              win32con.HWND_TOPMOST,  # 最上方
                              newx,  # 位置x
                              newy,  # 位置y
                              300,  # 长度
                              300,  # 宽度
                              win32con.SWP_SHOWWINDOW)
    print(SE)
Esempio n. 20
0
 def __call__(self, ensoapi):
     fore_win = DESK.GetForegroundWindow()
     win32gui.SetWindowPos(
         fore_win.GetHwnd(),
         win32con.HWND_TOPMOST,
         0,
         0,
         0,
         0,
         win32con.SWP_SHOWWINDOW | win32con.SWP_NOMOVE | win32con.SWP_NOSIZE)
     for win in DESK.GetTopLevelWindows():
         if win.GetTitle() in ('', 'Program Manager'):
             continue
         if is_app_window(win.GetHwnd()) and not is_maximized_window(win.GetHwnd()):
             win.Restore()
     fore_win.SetAsForegroundWindow()
     win32gui.SetWindowPos(
         fore_win.GetHwnd(),
         win32con.HWND_NOTOPMOST,
         0,
         0,
         0,
         0,
         win32con.SWP_SHOWWINDOW | win32con.SWP_NOMOVE | win32con.SWP_NOSIZE)
Esempio n. 21
0
def relocatewindow():
    # 定义结构体,存储当前窗口坐标
    class RECT(ctypes.Structure):
        _fields_ = [('left', ctypes.c_int), ('top', ctypes.c_int),
                    ('right', ctypes.c_int), ('bottom', ctypes.c_int)]

    rect = RECT()
    HWND = win32gui.GetForegroundWindow()  # 获取当前窗口句柄
    ctypes.windll.user32.GetWindowRect(HWND, ctypes.byref(rect))  # 获取当前窗口坐标
    win32gui.SetWindowPos(HWND, None, -6, 0, rect.right - rect.left,
                          rect.bottom - rect.top, win32con.SWP_NOSENDCHANGING
                          | win32con.SWP_SHOWWINDOW)  # 将窗口恢复至初始位置


#relocatewindow()
Esempio n. 22
0
    def xmax_currwin(self, event, spanMonitors=True, onlyEnd=False):
        mi = MONITORINFO(cbSize=ctypes.sizeof(MONITORINFO))
        guiti = GUITHREADINFO(cbSize=ctypes.sizeof(GUITHREADINFO))
        user.GetGUIThreadInfo(0, ctypes.byref(guiti))
        wi = WINDOWINFO()
        wi.cbSize = ctypes.sizeof(WINDOWINFO)
        win = guiti.hwndFocus
        user.GetWindowInfo(win, byref(wi))

        win = get_top_window(win)

        winr = RECT()
        user.GetWindowRect(win, ctypes.byref(winr))
        hMonitor = user.MonitorFromRect(ctypes.byref(winr), 0)
        res = user.GetMonitorInfoA(hMonitor, ctypes.byref(mi))

        curwidth = winr.right - winr.left
        absleft = mi.rcWork.left
        absright = mi.rcWork.right
        if spanMonitors:
            res = user.GetMonitorInfoA(self.monitors[0][0], ctypes.byref(mi))
            absleft = mi.rcWork.left
            res = user.GetMonitorInfoA(self.monitors[-1][0], ctypes.byref(mi))
            absright = mi.rcWork.right
        newleft = absleft
        newright = absright

        uFlags = win32con.SWP_ASYNCWINDOWPOS | win32con.SWP_NOACTIVATE

        if self.xmax_hist.has_key(win):
            oldr = self.xmax_hist[win]
            newleft = oldr.left
            newright = oldr.right
            del self.xmax_hist[win]
        else:
            self.xmax_hist[win] = winr
            if onlyEnd:
                uFlags |= win32con.SWP_NOMOVE
                newleft = winr.left

        newwidth = newright - newleft
        height = winr.bottom - winr.top

        res = win32gui.SetWindowPos(win, 0, newleft, winr.top, newwidth,
                                    height, uFlags)

        logging.info("xmax info: %s, %s, %s, %s, %s, %s", res, winr.dump(),
                     mi.rcWork.dump(), curwidth, newwidth, absleft)
Esempio n. 23
0
def run_assd(target="F"):

    tool, tool_path = tool_dic["ASSD"]
    run_tool(tool_path)
    #找到tool 所在的窗口
    hwnd = win32gui.FindWindow(None, tool)
    #设置assd窗口为焦点
    win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, 383, 140, 0, 0,
                          win32con.SWP_NOSIZE)

    hwndChildList = get_child_windows(hwnd)

    #磁盘选择窗口/磁盘名称窗口/开始按键
    disk_select = hwndChildList[10]
    write_aactime = hwndChildList[31]
    #选择待测试磁盘
    xy = button_center(disk_select)
    mouse_click(xy[0], xy[1])

    keybd_single_char("C")

    keybd_single_char(target)
    mouse_click(xy[0], xy[1])

    # 找到 start按键
    hwnd1 = win32gui.FindWindowEx(hwnd, None, None, "Start")
    xy = button_center(hwnd1)
    mouse_move(xy[0], xy[1])
    #开始运行
    mouse_click(xy[0], xy[1])
    while True:
        write_aactime_current = win32gui.GetWindowText(write_aactime)
        flag = 0
        #判断当前是否Acc time write 是否 为0
        if write_aactime_current != "0.000 ms":
            for cnt in range(0, 10):
                if write_aactime_current != win32gui.GetWindowText(
                        write_aactime):
                    break
                else:
                    flag = flag + 1
                    time.sleep(1)
        if flag == 10:
            break

    filename = "{}.bmp".format(tool)
    screenPrt.ScreenPrintWin().save_bitmap(bmp_filename=filename)
    close_window(tool)
Esempio n. 24
0
def set_borderless(hwnd, off=False):
    """Turn off / on titlebar and border"""

    borderless_style = (win32con.WS_BORDER | win32con.WS_THICKFRAME
                        | win32con.WS_CAPTION | win32con.WS_MAXIMIZE)
    current_style = win32gui.GetWindowLong(hwnd, win32con.GWL_STYLE)
    if off:
        style = current_style | borderless_style
    else:
        style = current_style & ~borderless_style

    win32gui.SetWindowLong(hwnd, win32con.GWL_STYLE, style)
    win32gui.SetWindowPos(
        hwnd, 0, 0, 0, 0, 0,
        win32con.SWP_FRAMECHANGED | win32con.SWP_NOMOVE | win32con.SWP_NOSIZE
        | win32con.SWP_NOZORDER | win32con.SWP_NOOWNERZORDER)
Esempio n. 25
0
File: hs.py Progetto: jufei/hs
    def activate_window(self, title, nx=-1, ny=-1):
        import os
        import win32gui
        import win32con

        hwnd = win32gui.FindWindow(None, title)
        win32gui.ShowWindow(hwnd, win32con.SW_RESTORE)  # Restore window
        win32gui.SetForegroundWindow(hwnd)  # Activate window
        rect = win32gui.GetWindowRect(hwnd)

        x = rect[0]
        y = rect[1]
        w = rect[2] - x
        h = rect[3] - y
        if nx <> -1:
            win32gui.SetWindowPos(hwnd, win32con.HWND_NOTOPMOST, x, 0, w, h, 0)
Esempio n. 26
0
 def update(self):
     """Update the window"""
     if self.__init is False:
         raise RuntimeError("Window is not initialized")
     if self._error is not None:
         self.destroy()
         self.__init = False
         raise Exception from self._error
     gui.UpdateWindow(self._window)
     gui.SetWindowPos(self._window, None, self._position[0],
                      self._position[1], 0, 0, con.SWP_NOSIZE)
     gui.SetLayeredWindowAttributes(self._window, 0x00ffffff, 0xff,
                                    con.LWA_COLORKEY | con.LWA_ALPHA)
     gui.RedrawWindow(self._window, None, None,
                      con.RDW_INVALIDATE | con.RDW_ERASE)
     gui.PumpWaitingMessages()
Esempio n. 27
0
def main():
    hwnd = win32gui.GetForegroundWindow()
    win32gui.SetWindowPos(hwnd,win32con.HWND_TOPMOST,1153,222,440,593,0)
    # Cleaning variables off the last run by set them all to None.
    set_all_variables_to_none()
    create_report_folder()
    # Initial values:
    config.MY_PROFILE_NAME = "XOwl"
    if input("Is my name: %s ?(Enter:yes/any keyword:no)"%config.MY_PROFILE_NAME) != "" :
        config.MY_PROFILE_NAME = input("Enter profile name: ")
    config.my_seat_number = 2 #int( input("My seat number? ") )
    config.bot_status = 'WAITING_FOR_FIRST_HAND'
    config.BLIND_VALUE = 100000000
    config.game_position = find_game_position.find_game_reference_point()

    start_the_bot()
Esempio n. 28
0
def main():
    hInstance = win32api.GetModuleHandle()
    className = 'MyWindowClassName'

    wndClass = win32gui.WNDCLASS()
    wndClass.style = win32con.CS_HREDRAW | win32con.CS_VREDRAW
    wndClass.lpfnWndProc = wndProc
    wndClass.hInstance = hInstance
    wndClass.hIcon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)
    wndClass.hCursor = win32gui.LoadCursor(None, win32con.IDC_ARROW)
    wndClass.hbrBackground = win32gui.GetStockObject(win32con.WHITE_BRUSH)
    wndClass.lpszClassName = className
    wndClassAtom = win32gui.RegisterClass(wndClass)

    exStyle = win32con.WS_EX_COMPOSITED | win32con.WS_EX_LAYERED | win32con.WS_EX_NOACTIVATE | win32con.WS_EX_TOPMOST | win32con.WS_EX_TRANSPARENT

    style = win32con.WS_DISABLED | win32con.WS_POPUP | win32con.WS_VISIBLE

    hWindow = win32gui.CreateWindowEx(
        exStyle,
        wndClassAtom,
        None,
        style,
        0,  # x
        0,  # y
        win32api.GetSystemMetrics(win32con.SM_CXSCREEN),  # width
        win32api.GetSystemMetrics(win32con.SM_CYSCREEN),  # height
        None,  # hWndParent
        None,  # hMenu
        hInstance,
        None  # lpParam
    )
    win32gui.SetLayeredWindowAttributes(hWindow, 0x00ffffff, 255,
                                        win32con.LWA_COLORKEY
                                        | win32con.LWA_ALPHA)  ####### COLOR

    win32gui.SetWindowPos(
        hWindow, win32con.HWND_TOPMOST, 0, 0, 0, 0, win32con.SWP_NOACTIVATE
        | win32con.SWP_NOMOVE | win32con.SWP_NOSIZE | win32con.SWP_SHOWWINDOW)
    thr = threading.Thread(target=customDraw, args=(hWindow, ))
    thr.setDaemon(False)
    thr.start()

    win32gui.ShowWindow(hWindow, win32con.SW_SHOWNORMAL)
    win32gui.UpdateWindow(hWindow)
    timer.set_timer(10000, customDraw)
    win32gui.PumpMessages()
Esempio n. 29
0
def run_ATTO_Disk_Benchmark(target="T"):

    tool = "Untitled - ATTO Disk Benchmark"
    tool_path = r'start "aa" "D:\SSD performance\ATTO Disk Benchmark\ATTODiskBenchmark.exe"'
    os.system(tool_path)
    time.sleep(5)
    #找到tool 所在的窗口
    hwnd = win32gui.FindWindow(None, tool)
    #设置窗口为焦点
    win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, 383, 0, 0, 0,
                          win32con.SWP_NOSIZE)

    assert win32gui.GetWindowText(hwnd) == tool, "run tool name wrong!"

    hwndChildList = get_child_windows(hwnd)

    disk_select = button_center(hwndChildList[2])
    mouse_move(disk_select[0], disk_select[1])
    keybd_single_char(target)
    time.sleep(0.5)

    start_button = button_center(hwndChildList[27])
    mouse_click(start_button[0], start_button[1])

    start_time = time.time()
    while win32gui.GetWindowText(hwndChildList[-10]) == "":
        time.sleep(1)
        elapsed_time = time.time() - start_time
        assert elapsed_time < 600, "timeout!"
        #print(type(win32gui.GetWindowText(hwndChildList[-10])))
    #print(win32gui.GetWindowText(hwndChildList[-10]))
    #print(type(win32gui.GetWindowText(hwndChildList[-10])))
    filename = "{}.png".format(tool)
    #调整截图边缘
    x1, y1, x2, y2 = win32gui.GetWindowRect(hwnd)
    x1 = x1 + 2
    x2 = x2 - 9
    y2 = y2 - 8
    time.sleep(1)
    screenshot(filename=filename, position=(
        x1,
        y1,
        x2,
        y2,
    ))

    print("run {} finished!".format(tool))
Esempio n. 30
0
    def start(self, recording=False, mode='sr'):
        self.sound_welcome.play()

        self.mode = mode

        # Set window transparency color
        hwnd = pygame.display.get_wm_info()["window"]
        gamewindow = win32gui.FindWindow(None,
                                         "PLAYERUNKNOWN'S BATTLEGROUNDS ")
        posX, posY, width, height = win32gui.GetWindowPlacement(gamewindow)[4]

        windowStyles = win32con.WS_EX_LAYERED | win32con.WS_EX_TRANSPARENT

        win32gui.SetWindowLong(
            hwnd, win32con.GWL_EXSTYLE,
            win32gui.GetWindowLong(hwnd, win32con.GWL_EXSTYLE)
            | win32con.WS_EX_LAYERED)
        win32gui.SetLayeredWindowAttributes(
            hwnd, win32api.RGB(*colors.get("fuschia")), 0,
            win32con.LWA_COLORKEY)
        win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, posX, posY, 0, 0,
                              win32con.SWP_NOSIZE)

        # windowAlpha = 180
        # win32gui.SetLayeredWindowAttributes(hwnd, win32api.RGB(0,0,0),
        # windowAlpha, win32con.LWA_ALPHA)

        longrange_text = self.myfont.render('LONG RANGE MODE', False,
                                            (255, 0, 255))
        shortrange_text = self.myfont.render('SHORT RANGE MODE', False,
                                             (255, 0, 255))

        i = 0
        self.tick = 0
        while not self.done:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self.done = True
            self.screen.fill(colors.get('fuschia'))  #transparent background
            self.draw_hud(mode)
            pygame.display.update()
            if (i == 0):
                i = 1
            else:
                i = 0

        return