Ejemplo n.º 1
0
# 用于寻找良好区分各个块的像素点,不参与实际运行
import numpy as np
import win32gui
from PIL import ImageGrab
import matplotlib.pyplot as plt

board = np.zeros((16, 30), dtype=int)
title_name = "扫雷"
hwnd = win32gui.FindWindow(None, title_name)  # 获得窗口

left, top, right, bottom = win32gui.GetWindowRect(hwnd)  # 窗口大小
left = left + 15
top = top + 101
right = right - 11
bottom = bottom - 11
image = ImageGrab.grab((left, top, right, bottom))
image = np.array(image)

# 更新board的内容
max = 0
max_x, max_y = 0, 0
max_pixel = []
for offset in range(16 * 16):
    pixel_values = []
    i = 0
    offset_x, offset_y = 0, 0
    while i < 256:
        j = 0
        while j < 480:
            offset_x, offset_y = offset // 16, offset % 16
            pixel_value = image[i + offset_x, j + offset_y, :]
Ejemplo n.º 2
0
import tensorflow as tf
from keras.models import load_model
import win32gui
import time
import keras
import gc
from grabscreen import grab_screen
import cv2
from pynput.keyboard import Key, Controller

model = load_model('kerasAECD2')

try:
    hwnd = win32gui.FindWindow(None, 'Not Tetris 2')
    find_region = win32gui.GetWindowRect(hwnd)
except:
    find_region = (0,0,100,100)
left,top,x2,y2 = find_region


for i in list(range(4))[::-1]:
        print(i+1)
        time.sleep(1)
work = True
while work:
    image = grab_screen(region=(left+3,top+25,x2-196,y2-1))
    image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    
    cv2.imshow('cd', image)    
    image = cv2.resize(image,(32,44))   
    image = image/255.0
Ejemplo n.º 3
0
    elif demonet == 'res101':
        net = Resnet101(batch_size=1)
    else:
        raise NotImplementedError

    net.create_architecture(sess,
                            "TEST",
                            len(CLASSES),
                            tag='default',
                            anchor_scales=cfg.ANCHOR_SCALES,
                            anchor_ratios=cfg.ANCHOR_RATIOS)
    saver = tf.train.Saver()
    saver.restore(sess, tfmodel)

    print('Loaded network {:s}'.format(tfmodel))

    rect, hwnd = get_win_dims('欢乐麻将全集')

    win32gui.SetWindowPos(hwnd, win32con.HWND_NOTOPMOST, 0, 0,
                          rect[2] - rect[0], rect[3] - rect[1], 0)
    rect = win32gui.GetWindowRect(hwnd)
    mngr = plt.get_current_fig_manager()
    mngr.window.setGeometry(rect[2], 50, WIN_WIDTH, WIN_HEIGHT)

    ani = animation.FuncAnimation(fig,
                                  updatefig,
                                  interval=400,
                                  blit=True,
                                  fargs=(hwnd, rect, sess, net))
    plt.show()
Ejemplo n.º 4
0
def GetRect(osHandlerModel):
    (left, top, right,
     bottom) = win32gui.GetWindowRect(osHandlerModel.GetHandlePtr())
    return (left, top, right, bottom)
Ejemplo n.º 5
0
 def _click_login_verify_code(self):
     input_hwnd = win32gui.GetDlgItem(self.login_hwnd, 0x56ba)
     rect = win32gui.GetWindowRect(input_hwnd)
     self._mouse_click(rect[0] + 5, rect[1] + 5)
Ejemplo n.º 6
0
import win32gui
from PIL import ImageGrab
import win32con
import time
from pynput.mouse import Button, Controller
import aotopy
mouse = Controller()

__hwnd = win32gui.FindWindow(0, "梦幻西游 ONLINE - (江苏3区[春风十里] - ㄧ赖Ⅵ雪慈[42022437])")
if not __hwnd:
    print('window not found!')
    exit()
win32gui.SetForegroundWindow(__hwnd)
win32gui.ShowWindow(__hwnd, win32con.SW_RESTORE)
gamerect = win32gui.GetWindowRect(__hwnd)  #(left, top, right, bottom)
hcenter = int((gamerect[2] - gamerect[0]) / 2) + gamerect[0]
vcenter = int((gamerect[3] - gamerect[1]) / 2) + gamerect[1]
time.sleep(10)
mouse.position = (hcenter, vcenter)  #initialize mouse position
print(gamerect)
print(hcenter, ' ', vcenter)

# from pynput import mouse

# def on_move(x, y):
#     print('Pointer moved to {0}'.format(
#         (x, y)))

# def on_click(x, y, button, pressed):
#     print('{0} at {1}'.format(
#         'Pressed' if pressed else 'Released',
Ejemplo n.º 7
0
def get_window_position():
    window = win32gui.GetForegroundWindow()
    window_rect = win32gui.GetWindowRect(window)
    win32gui.SetForegroundWindow(window)
    return window_rect
Ejemplo n.º 8
0
# Scroll two steps down
mouse.scroll(0, 2)

import win32gui
from PIL import ImageGrab
import win32con
import time

__hwnd = win32gui.FindWindow(0, "天涯明月刀")
if not __hwnd:
    print('window not found!')
    exit()

win32gui.SetForegroundWindow(__hwnd)
win32gui.ShowWindow(__hwnd, win32con.SW_RESTORE)
__game_rect = win32gui.GetWindowRect(__hwnd)

input('waiting for running!')
__adj_game_rect = (__game_rect[0] + 5, __game_rect[1] + 35, __game_rect[2] - 5,
                   __game_rect[3] - 10)


def getScreen():
    src_image = ImageGrab.grab(__adj_game_rect)
    return src_image


if __name__ == '__main__':
    getScreen()
Ejemplo n.º 9
0
 def winRect():
     return win32gui.GetWindowRect(Window.id)
Ejemplo n.º 10
0
instr = input("Please input task times : ")
if instr:
    qilincnt, yuhuncnt, tansuocnt = (int(x) for x in instr.split(' '))
else:
    qilincnt = 1
    yuhuncnt = 3
    tansuocnt = 3
#(int(x) for x in input("Please input task times : ").split(' '))
#abc =map(int, input("Please input : ").split())

# 获取窗口句柄及位置
clsname = "Qt5QWindowIcon"
tlename = "夜神模拟器"
hwnd = win32gui.FindWindow(clsname, tlename)
if hwnd != None:
    posbase = win32gui.GetWindowRect(hwnd)
else:
    print("Warning: fail to find the window!!!")

# 假定一个初始状态,但随后被更新了
taskNow = -1

while (hwnd != None):
    # 记录时间
    begin_time = time.time()
    #截图
    img = ImageGrab.grab(posbase)
    #从图片格式像素[R,G,B]转化数组
    imary = np.array(img)
    #讲像素通道分离
    [r, g, b] = cv2.split(imary)
Ejemplo n.º 11
0
def getRect(hwnd):
    import win32gui
    # 获取窗口左上角和右下角坐标
    return win32gui.GetWindowRect(hwnd)
Ejemplo n.º 12
0
    def _window_enum_callback(self, hwnd, wildcard):

        if win32gui.IsWindowVisible(hwnd) != 0:
            (s_x, s_y, e_x, e_y) = win32gui.GetWindowRect(hwnd)
            w_width = e_x - s_x
            w_height = e_y - s_y
            # print(str(win32gui.GetWindowText(hwnd)) + '[' + str ( (s_x, s_y) ) + '] [' + str( (w_width, w_height) ) + ']')

        if re.match(wildcard, str(win32gui.GetWindowText(
                hwnd))) != None and win32gui.IsWindowVisible(hwnd) != 0:
            # print('--------------------> !!! found window DEBUG2 new : ', wildcard, str(win32gui.GetWindowText(hwnd)), ':', self.handle_list, ':')
            if not hwnd in self.handle_list:
                (top_left_x, top_left_y, bottom_right_x,
                 bottom_right_y) = win32gui.GetWindowRect(hwnd)
                # print('--------------------> !!! found window DEBUG3 new : ', (top_left_x, top_left_y, bottom_right_x, bottom_right_y))
                # print(win32gui.GetWindowText(hwnd), abs(bottom_right_y - top_left_y))

                if (abs(bottom_right_x - top_left_x - LYBWin.WIDTH) < 100
                        and abs(bottom_right_y - top_left_y - LYBWin.HEIGHT) <
                        100):

                    diff_width = abs(top_left_x - bottom_right_x)
                    diff_height = abs(bottom_right_y - top_left_y)

                    print(win32gui.GetWindowText(hwnd), diff_width,
                          diff_height)

                    if diff_height == LYBWin.HEIGHT + 34 and diff_width == LYBWin.WIDTH + 4:
                        # 녹스 FHD
                        self.handle_list.append(hwnd)
                    elif diff_height == LYBWin.HEIGHT + 50 and diff_width == LYBWin.WIDTH + 4:
                        # 녹스 UHD
                        self.handle_list.append(hwnd)
                    elif diff_height == LYBWin.HEIGHT + 38 and diff_width == LYBWin.WIDTH + 38:
                        # LDPlayer FHD
                        win32gui.EnumChildWindows(
                            hwnd, self.callback_momo_child_process, hwnd)
                    elif diff_height == LYBWin.HEIGHT + 56 and diff_width == LYBWin.WIDTH + 56:
                        # LDPlayer UHD
                        win32gui.EnumChildWindows(
                            hwnd, self.callback_momo_child_process, hwnd)
                    elif diff_height == LYBWin.HEIGHT + 30 and diff_width == LYBWin.WIDTH + 38:
                        # MEmu FHD Portrait
                        win32gui.EnumChildWindows(
                            hwnd, self.callback_memu_child_process, hwnd)
                    elif diff_height == LYBWin.HEIGHT + 34 and diff_width == LYBWin.WIDTH + 40:
                        # MEmu FHD Landscape
                        win32gui.EnumChildWindows(
                            hwnd, self.callback_memu_child_process, hwnd)
                    elif abs(bottom_right_y -
                             top_left_y) == LYBWin.HEIGHT + 38:
                        # LDPlayer FHD
                        win32gui.EnumChildWindows(
                            hwnd, self.callback_momo_child_process, hwnd)
                    elif abs(bottom_right_y -
                             top_left_y) == LYBWin.HEIGHT + 56:
                        # LDPlayer UHD
                        win32gui.EnumChildWindows(
                            hwnd, self.callback_momo_child_process, hwnd)
                    elif abs(bottom_right_y -
                             top_left_y) == LYBWin.HEIGHT + 34:
                        # Nox FHD
                        self.handle_list.append(hwnd)
                    elif abs(bottom_right_y -
                             top_left_y) == LYBWin.HEIGHT + 37:
                        # Nox UHD
                        self.handle_list.append(hwnd)
                        # win32gui.EnumChildWindows(hwnd, self.callback_nox_child_process, hwnd)
                    elif abs(bottom_right_y -
                             top_left_y) == LYBWin.HEIGHT + 50:
                        # Nox UHD
                        self.handle_list.append(hwnd)
                        # win32gui.EnumChildWindows(hwnd, self.callback_nox_child_process, hwnd)
                    elif abs(bottom_right_x - top_left_x) == LYBWin.WIDTH + 40:
                        # Memu
                        win32gui.EnumChildWindows(
                            hwnd, self.callback_memu_child_process, hwnd)

                        # if re.match('Nox', str(win32gui.GetWindowText(hwnd))):
                        #     print('Nox 사이드 바: ', str(win32gui.GetWindowText(hwnd)), win32gui.IsWindowVisible(hwnd))

        if win32gui.IsWindowVisible(hwnd) != 0:
            # 녹스 사이드 바 이름 변경됨 6.0.5.1
            if (re.match('nox', str(win32gui.GetWindowText(hwnd))) is not None
                    or re.match('Nox', str(
                        win32gui.GetWindowText(hwnd))) is not None
                    or re.match('Form', str(
                        win32gui.GetWindowText(hwnd))) is not None):
                print('--------------------> !!! found window DEBUG4 Nox : ',
                      str(win32gui.GetWindowText(hwnd)))
                if hwnd not in self.side_window_handle_list:
                    (top_left_x, top_left_y, bottom_right_x,
                     bottom_right_y) = win32gui.GetWindowRect(hwnd)
                    print(
                        '--------------------> !!! found window DEBUG5 Nox : ',
                        (top_left_x, top_left_y, bottom_right_x,
                         bottom_right_y))
                    if abs(bottom_right_x - top_left_x) - 36 < 100 and abs(
                            bottom_right_y - top_left_y - LYBWin.HEIGHT) < 80:
                        self.side_window_handle_list.append(hwnd)
                        #
                        # 모모 멀티플레이어
                        # if win32gui.IsWindowVisible(hwnd) != 0:
            if lybconstant.LYB_MULTI_APP_PLAYER_NAME_MOMO in str(
                    win32gui.GetWindowText(hwnd)):
                self.multi_window_handle_dic[
                    lybconstant.LYB_MULTI_APP_PLAYER_NAME_MOMO] = hwnd

            # 미뮤 멀티
            if lybconstant.LYB_MULTI_APP_PLAYER_NAME_MEMU in str(
                    win32gui.GetWindowText(hwnd)):
                self.multi_window_handle_dic[
                    lybconstant.LYB_MULTI_APP_PLAYER_NAME_MEMU] = hwnd

            # 녹스 멀티앱플레이어
            if lybconstant.LYB_MULTI_APP_PLAYER_NAME_NOX in str(
                    win32gui.GetWindowText(hwnd)):
                # print(str(lybconstant.LYB_MULTI_APP_PLAYER_NAME_NOX) + ':[' + str(win32gui.GetWindowText(hwnd)) + '][' + str ( (s_x, s_y) ) + '] [' + str( (w_width, w_height) ) + ']')
                self.multi_window_handle_dic[
                    lybconstant.LYB_MULTI_APP_PLAYER_NAME_NOX] = hwnd

        if re.match(self.my_name, str(win32gui.GetWindowText(
                hwnd))) != None and win32gui.IsWindowVisible(hwnd) != 0:
            self.my_handle = hwnd
Ejemplo n.º 13
0
def CaptureScreen():
    HWND = win32gui.GetFocus()  #获取当前窗口句柄
    rect = win32gui.GetWindowRect(HWND)  #获取当前窗口坐标
    im = ImageGrab.grab(rect)  #截取目标图像
    im.save("second.jpeg", 'jpeg')  #前面一个参数是保存路径,后面一个参数是保存格式
Ejemplo n.º 14
0
def move_wnd(handle_par, x, y):
    left, top, right, bottom = win32gui.GetWindowRect(handle_par)
    win32gui.MoveWindow(handle_par, x, y, right - left, bottom - top, True)
Ejemplo n.º 15
0
import Find_All_Handler
import win32gui, win32api, win32con
import time
from gtools import *


def get_hwnd_child(fhwnd):
    hwndChildList = []
    win32gui.EnumChildWindows(fhwnd, lambda hwnd, param: param.append(hwnd),
                              hwndChildList)
    return hwndChildList


main_handle = find_windows(title='东方财富终端')[0]
process = win32process.GetWindowThreadProcessId(main_handle)[1]
handles = find_windows(process=process,
                       class_name='#32770',
                       top_level_only=True,
                       visible=True,
                       title='')
print(handles)
handle = handles[0]
rect = win32gui.GetWindowRect(handle)
win32gui.MoveWindow(handle, 0, 0, rect[2] - rect[0], 756, True)
Ejemplo n.º 16
0
def main():

    # プリコネ起動→ウィンドウのハンドル取得→画面取得
    prkn_handle = win32gui.FindWindow(None, "PrincessConnectReDive")
    if prkn_handle <= 0:
        subprocess.Popen(
            'start dmmgameplayer://priconner/cl/general/priconner', shell=True)
        tm.sleep(10)  # 起動にこれくらいかかるのでとりあえず待つ

    # ウィンドウ名でハンドル取得
    while (True):
        prkn_handle = win32gui.FindWindow(None, "PrincessConnectReDive")
        if prkn_handle > 0:
            break

        print("プリコネが起動してないよー")
        tm.sleep(3)

    print("プリコネが起動してるよー")
    frame_rate = 30

    video_type = RESOLUTION_16_9
    CHARACTERS_DATA, SEC_DATA, MENU_DATA, SCORE_DATA, DAMAGE_DATA, ICON_DATA = model_init(
        video_type)
    UB_ROI, MIN_ROI, TEN_SEC_ROI, ONE_SEC_ROI, MENU_ROI, SCORE_ROI, DAMAGE_DATA_ROI, CHARACTER_ICON_ROI, MENU_LOC, FRAME_THRESH = roi_init(
        video_type)

    n = 0.34  # n秒ごと*
    ub_interval = 0

    time_min = "1"
    time_sec10 = "3"
    time_sec1 = "0"

    menu_check = False

    min_roi = MIN_ROI
    tensec_roi = TEN_SEC_ROI
    onesec_roi = ONE_SEC_ROI
    ub_roi = UB_ROI
    score_roi = SCORE_ROI
    damage_data_roi = DAMAGE_DATA_ROI

    ub_data = []
    ub_data_value = []
    time_data = []
    characters_find = []

    tmp_damage = []
    total_damage = False

    cap_interval = int(frame_rate * n)
    skip_frame = 5 * cap_interval

    try:
        while (True):
            tm.sleep(n)

            rect_left, rect_top, rect_right, rect_bottom = win32gui.GetWindowRect(
                prkn_handle)

            # 微妙に外枠がとれちゃうので1280x720の位置補正
            cap_left = rect_left + 8
            cap_top = rect_top + 32
            cap_right = cap_left + 1280
            cap_bottom = cap_top + 720

            # 指定した領域内をクリッピング
            img = ImageGrab.grab(bbox=(cap_left, cap_top, cap_right,
                                       cap_bottom))
            original_frame = np.array(img)  # video.read()と同等のデータ取得

            work_frame = edit_frame(original_frame)

            if menu_check is False:
                menu_check, menu_loc = analyze_menu_frame(
                    work_frame, MENU_DATA, MENU_ROI)
                if menu_check is True:
                    print("画面右上のMENUが見つかったよー。\nTLの記録を開始するよー")
                    loc_diff = np.array(MENU_LOC) - np.array(menu_loc)
                    roi_diff = (loc_diff[0], loc_diff[1], loc_diff[0],
                                loc_diff[1])
                    min_roi = np.array(MIN_ROI) - np.array(roi_diff)
                    tensec_roi = np.array(TEN_SEC_ROI) - np.array(roi_diff)
                    onesec_roi = np.array(ONE_SEC_ROI) - np.array(roi_diff)
                    ub_roi = np.array(UB_ROI) - np.array(roi_diff)
                    score_roi = np.array(SCORE_ROI) - np.array(roi_diff)
                    damage_data_roi = np.array(DAMAGE_DATA_ROI) - np.array(
                        roi_diff)

                    analyze_anna_icon_frame(work_frame, CHARACTER_ICON_ROI,
                                            characters_find)

            else:
                if time_min == "1":
                    time_min = analyze_timer_frame(work_frame, min_roi, 2,
                                                   time_min)

                time_sec10 = analyze_timer_frame(work_frame, tensec_roi, 6,
                                                 time_sec10)
                time_sec1 = analyze_timer_frame(work_frame, onesec_roi, 10,
                                                time_sec1)

                ub_result = analyze_ub_frame(work_frame, ub_roi, time_min,
                                             time_sec10, time_sec1, ub_data,
                                             ub_data_value, characters_find)

                if ub_result is FOUND:
                    tm.sleep(1.66)  # 50フレーム(秒)

                # スコア表示の有無を確認(クラバト)
                ret = analyze_score_frame(work_frame, SCORE_DATA, score_roi)

                if ret is True:
                    # 総ダメージ解析
                    ret = analyze_damage_frame(original_frame, damage_data_roi,
                                               tmp_damage)

                    if ret is True:
                        total_damage = "総ダメージ " + ''.join(tmp_damage)

                    break

        output_result(ub_data, ub_data_value, characters_find)

    except KeyboardInterrupt:
        output_result(ub_data, ub_data_value, characters_find)
        exit(0)
Ejemplo n.º 17
0
 def _grab_verify_code(self):
     verify_code_hwnd = win32gui.GetDlgItem(self.login_hwnd, 0x56ba)
     self._set_foreground_window(self.login_hwnd)
     time.sleep(1)
     rect = win32gui.GetWindowRect(verify_code_hwnd)
     return ImageGrab.grab(rect)
Ejemplo n.º 18
0
def get_win_image(handle):
    hwnd = win32gui.FindWindow(handle, None)
    left, top, right, bot = win32gui.GetWindowRect(hwnd)
    im = ImageGrab.grab((left, top, right, bot))
    return im
Ejemplo n.º 19
0
 def ms_get_screen_rect(self, hwnd):
     return win32gui.GetWindowRect(hwnd)
Ejemplo n.º 20
0
#    time.sleep(0.01) #wait a bit for animations to finish ~0.01s


###############################################################################
def checkSafe():
    for y in arange(tot_y):
        for x in arange(tot_x):
            if safe[y, x] == 1 and Board[y, x] == 10:
                openSpace(first_left + x * dx, first_top + y * dx)


###############################################################################

Minesweeper = win32gui.FindWindow(None, 'Minesweeper')
left, top, right, bot = win32gui.GetWindowRect(Minesweeper)
w = right - left
h = bot - top
first_left = left + 47
first_top = top + 89  #first space 47;89
dx = 18  #pixels between spaces

openSpace(left, top)
openSpace(first_left + 7 * dx, first_top + 7 * dx)  #Open the first space
time.sleep(0.15)  #wait for the fancy animation to end ~0.15s

mines = zeros(
    (tot_y, tot_x)
)  #array for checking mines so that program doesn't mark the same one two times
solved = zeros(
    (tot_y,
Ejemplo n.º 21
0
def dujitang():#毒鸡汤
    url = 'https://8zt.cc/'
    res = requests.get(url=url, headers=headers, timeout=10)
    selector = etree.HTML(res.text)
    # content = selector.xpath('//section/div/*/text()')[0]
    content = selector.xpath('//div[@class="main-wrapper"]//span[@id="sentence"]/text()')[0]
    #text = str(content)
    return content

#######################发送过程=================
#查找微信窗口,如果最小化则还原(需要固定位置)
title_name="张三"#需要单独打开张三的对话框,好友名称
win = win32gui.FindWindow('ChatWnd',title_name)
print("找到句柄:%x" % win)
if win!=0:
    left, top, right, bottom = win32gui.GetWindowRect(win)
    print(left, top, right, bottom)#最小化为负数
    print("nothe")
    #
    #最小化时点击还原,下面为单个窗口
    if top<0:
        #鼠标点击,还原窗口
        win32api.SetCursorPos([190, 1040])  # 鼠标定位到(190,1040)
        # 执行左单键击,若需要双击则延时几毫秒再点击一次即可
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP | win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
        ######点击完成一次
    time.sleep(0.5)
    left, top, right, bottom = win32gui.GetWindowRect(win)#取数
    #
    #最小时点击还原窗口,下面一节为多个窗口,依次点击打开。
    k=1040#最小化后的纵坐标,横坐标约为190
win32gui.EnumWindows(enum_win, toplist)

# print(windows_list)

# Game handle
game_hwnd = 0
for (hwnd, win_text) in windows_list:
    if "Photos" in win_text:
        game_hwnd = hwnd

while True:
    # Change the line below depending on whether you want the whole window
    # or just the client area.
    #left, top, right, bot = win32gui.GetClientRect(game_hwnd)
    left, top, right, bot = win32gui.GetWindowRect(game_hwnd)
    position = win32gui.GetWindowRect(game_hwnd)
    w = right - left
    h = bot - top

    hwndDC = win32gui.GetWindowDC(game_hwnd)
    mfcDC = win32ui.CreateDCFromHandle(hwndDC)
    saveDC = mfcDC.CreateCompatibleDC()

    saveBitMap = win32ui.CreateBitmap()
    saveBitMap.CreateCompatibleBitmap(mfcDC, w, h)

    saveDC.SelectObject(saveBitMap)

    # Change the line below depending on whether you want the whole window
    # or just the client area.
Ejemplo n.º 23
0
def getCentre(hwnd):
    _left, _top, _right, _bottom = win32gui.GetWindowRect(hwnd)
    centreX = (_right - _left) // 2 + _left
    centreY = (_bottom - _top) // 2 + _top
    return (centreX, centreY)
def reset_pos(x, y):
    hwnd = win32gui.FindWindow('地下城与勇士', None)
    rect = win32gui.GetWindowRect(hwnd)
    win32gui.SetWindowPos(hwnd, -2, x, y, rect[2] - rect[0], rect[3] - rect[1],
                          64)
Ejemplo n.º 25
0
def get_handle(resolution=[1920, 1080],
               order=0,
               sim="ANY"):  #now only the 夜神 is supported
    # sim : ANY表示为任何第一个检测到的窗体, 其余为config上的第一个名称
    handlelist = []
    handle_infor = globalvar.get_handle_infor()
    win32gui.EnumWindows(
        lambda hWnd, param: param.append(
            [hWnd,
             win32gui.GetClassName(hWnd),
             win32gui.GetWindowText(hWnd)]), handlelist)
    exist = False
    for i in range(0, len(handle_infor), 2):
        win = win32gui.FindWindow(None, handle_infor[i])
        if win == 0:
            continue
        else:
            if handle_infor[i + 1] == 'None':
                if sim in ['ANY', handle_infor[i]]:
                    tmp_list = []
                    exist = True
                    for i1, i2, i3 in handlelist:
                        if i3 == handle_infor[i]:
                            tmp_list.append(i1)
                    win = tmp_list[order]
                    break
                else:
                    continue
            else:
                hWndChildList = []
                win32gui.EnumChildWindows(
                    win, lambda hWnd, param: param.append([
                        hWnd,
                        win32gui.GetClassName(hWnd),
                        win32gui.GetWindowText(hWnd)
                    ]) if win32gui.GetWindowText(hWnd) in
                    [handle_infor[i + 1]] else None, hWndChildList)
                try:
                    win = hWndChildList[0][0]
                    print("当前检测到{}".format(handle_infor[i]))
                    if sim in ['ANY', handle_infor[i]]:
                        exist = True
                        break
                    else:
                        continue
                except:
                    continue
    if exist == False:
        return -1
    # win = win32gui.FindWindow(None, handle_infor[0])
    # if win==0:
    #     win = win32gui.FindWindow(None, handle_infor[2])
    #     hWndChildList = []
    #     win32gui.EnumChildWindows(win, lambda hWnd, param: param.append([hWnd
    #                                                                         , win32gui.GetClassName(hWnd)
    #                                                                         , win32gui.GetWindowText(hWnd)])
    #     if win32gui.GetWindowText(hWnd) in [handle_infor[3]]  else None, hWndChildList)
    #     try:
    #         win = hWndChildList[0][0]
    #         print("当前为mumu模拟器")
    #     except:
    #         return -1

    # else:
    #     hWndChildList = []
    #     win32gui.EnumChildWindows(win, lambda hWnd, param: param.append([hWnd
    #                                                                         , win32gui.GetClassName(hWnd)
    #                                                                         , win32gui.GetWindowText(hWnd)])
    #     if win32gui.GetWindowText(hWnd) in ['QWidgetClassWindow',handle_infor[1]]  else None, hWndChildList)
    #     try:
    #         win = hWndChildList[0][0]
    #         print("当前为夜神模拟器")
    #     except:
    #         return -1

    # rect = win32gui.GetWindowRect(win)
    hwndDC = win32gui.GetDC(0)
    defalut_xdpi = 96
    default_ydpi = 96
    # 创建设备描述表
    x_dpi = win32print.GetDeviceCaps(hwndDC, win32con.LOGPIXELSX)
    y_dpi = win32print.GetDeviceCaps(hwndDC, win32con.LOGPIXELSY)
    print("x轴dpi{}".format(x_dpi))
    print("y轴dpi{}".format(y_dpi))
    left, top, right, bot = win32gui.GetWindowRect(win)
    # w = int((right - left) * (x_dpi/defalut_xdpi))
    # h = int((bot - top) * (y_dpi/default_ydpi))
    w = int((right - left))
    h = int((bot - top))
    globalvar.set_window_resolution([w, h])
    print("当前窗体大小为{}x{}".format(w, h))
    if w == resolution[0] and h == resolution[1]:
        pass
    else:
        #print('resolution isn\'t {}p'.format(resolution[1]))
        pass
    return win
Ejemplo n.º 26
0
            if bt_window > 0:
                logged_in = True
                logging.info('logging No.' + str(player_id) + ' player succeeded!')
                break
        if not logged_in:
            kill_process('Battle.net.exe', '暴雪战网登录')
            logging.warning('log No.' + str(player_id) + ' player failed!')
        if time.time() - logging_time >= 600:
            # after 10 minutes failure, terminate program
            logging.warning('logging keeps failing, terminated!')
            sys.exit()

    # logged in Battle net!!!
    # move bn window to 0,0
    win32gui.SetForegroundWindow(bt_window)
    bt_rec = win32gui.GetWindowRect(bt_window)
    win32gui.MoveWindow(bt_window, 0, 0, bt_rec[2] - bt_rec[0], bt_rec[3] - bt_rec[1], 1)
    time.sleep(1)

    # looking for hs and click waiting for hs
    hs_png = 'hs' + suffix + '.png'
    while True:
        found = pyautogui.locateCenterOnScreen(hs_png, region=(0, 0, bt_rec[2], bt_rec[3]),
                                               grayscale=False, confidence=0.9)
        if found is not None:
            x = found[0]
            y = found[1]
            break

    logging.info('hs logo found in (' + str(x) + ', ' + str(y) + ')!')
    pyautogui.moveTo(x, y, 1,  pyautogui.easeInQuad)
Ejemplo n.º 27
0
 def GetWindowSizes(self):
     win32gui.GetWindowRect(self.hwnd)
Ejemplo n.º 28
0
import time
import os

import win32gui
from PIL import ImageGrab


game_name = "League of Legends (TM) Client"
client_name = "League of Legends"
save_dir = "images"
handle1 = win32gui.FindWindow(None, client_name)
if handle1:
    client_size = win32gui.GetWindowRect(handle1)
    if (client_size[2] - client_size[0]) != 1280 and \
            (client_size[3] - client_size[1]) != 720:
        hwndChildLIst = []
        win32gui.EnumChildWindows(
            handle1, lambda hwnd, param: param.append(hwnd), hwndChildLIst)
        for i in hwndChildLIst:
            s = win32gui.GetWindowRect(i)
            if (s[2] - s[0]) == 1280 and (s[3] - s[1]) == 720:
                handle1 = i
                break

handle2 = win32gui.FindWindow(None, game_name)
print(handle1, handle2)
handle = max(handle1, handle2)
window_position = win32gui.GetWindowRect(handle)
win32gui.SetForegroundWindow(handle)
time.sleep(1)
ImageGrab.grab(window_position).save(
Ejemplo n.º 29
0
def get_win_dims(name):
    hwnd = win32gui.FindWindow(None, name)
    rect = win32gui.GetWindowRect(hwnd)
    print(rect)
    return rect, hwnd
Ejemplo n.º 30
0
from PIL import ImageGrab
import numpy as np
import win32gui
import cv2

window_position = win32gui.FindWindow(None, r'Mirror')
window_dimensions = win32gui.GetWindowRect(window_position)
distance_left, distance_top, window_width, window_height = window_dimensions
cropped_window_dimensions = (distance_left + 5, distance_top + 26,
                             window_width - 2, window_height - 3)
game_frame = ImageGrab.grab(cropped_window_dimensions)
game_frame = np.array(game_frame)
ix, iy = -1, -1


# Mouse callback function
def draw_circle(event, x, y, flags, param):
    global ix, iy
    if event == cv2.EVENT_LBUTTONDBLCLK:
        cv2.circle(img, (x, y), 1, (255, 0, 0), 2)
        ix, iy = x, y


# Create a black image, a window and bind the function to window
img = game_frame
cv2.namedWindow('Frame Debugger')
cv2.setMouseCallback('Frame Debugger', draw_circle)

while True:
    cv2.imshow('Frame Debugger', img)
    k = cv2.waitKey(20) & 0xFF