コード例 #1
0
 def SetAsForegroundWindow(cls, hwnd):
     #发送ALT键,ALT键使用%号表示
     cls.shell.SendKeys('%')
     win32gui.SetForegroundWindow(hwnd)
コード例 #2
0
def set_forground(h_wnd: int) -> None:
    win32gui.SetForegroundWindow(h_wnd)
コード例 #3
0
ファイル: companyfillanjuke.py プロジェクト: mktsyy/codes
# #-*-coding:utf-8-*-
import os
import time
import win32gui
import win32api
import win32con
import time

wdname1 = u"房源发布 - 租房 - 中国网络经纪人 - Cent Browser"
w1hd = win32gui.FindWindow(0, wdname1)

#获取窗口焦点
w2hd = win32gui.FindWindowEx(w1hd, None, None, None)
win32gui.SetForegroundWindow(w2hd)
time.sleep(0.2)

# #获取当前坐标
print win32gui.GetCursorPos()

# #房屋户型-室
# # win32api.SetCursorPos([572,605])
# # win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
# # time.sleep(0.05)
# # win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)
# # time.sleep(0.05)
# # #快捷键2
# # win32api.keybd_event(50,0,0,0)
# # win32api.keybd_event(50,0,win32con.KEYEVENTF_KEYUP,0)

# # #房屋户型 -厅
# # win32api.SetCursorPos([705, 607])
コード例 #4
0
        openfile.truncate()
        openfile.write(str(tokenuser)[2:-1])
        openfile.close()
        openfile = open(passfile, 'w')
        openfile.truncate()
        openfile.write(str(tokenpass)[2:-1])
        openfile.close()
        openfile = open(keyfile, 'w')
        openfile.truncate()
        openfile.write(str(tokenkey)[2:-1])
        openfile.close()
        print(f.decrypt(tokenpass))
    elif "p" in sys.argv or "P" in sys.argv or "-p" in sys.argv or "-P" in sys.argv:
        username, password = getcred()
        #pyautogui.typewrite(password)

else:
    time.sleep(2)
    x = win32gui.GetForegroundWindow()
    #x = 524822
    #print(str(x))
    win32gui.SetActiveWindow(x)
    win32gui.SetForegroundWindow(x)
    username, password = getcred()
    time.sleep(.1)
    #pyautogui.typewrite(username)
    #pyautogui.press('tab')
    time.sleep(.1)
    #pyautogui.typewrite(password)
    pyautogui.typewrite("1")
    y = input("All done.")
コード例 #5
0
ファイル: 练习1.py プロジェクト: zengyufei/pycharm
import win32api
import win32gui
import win32process

import win32con

# 根据类名及标题名查询句柄,
hwnd = win32gui.FindWindow("WeChatMainWndForPC", "微信")
hreadID, processID = win32process.GetWindowThreadProcessId(hwnd)

print(hwnd)
print(hreadID)
print(processID)

# 没有直接修改窗口大小的方式,但可以曲线救国,几个参数分别表示句柄,起始点坐标,宽高度,是否重绘界面 ,如果想改变窗口大小,就必须指定起始点的坐标,没果对起始点坐标没有要求,随便写就可以;如果还想要放在原先的位置,就需要先获取之前的边框位置,再调用该方法即可
# win32gui.MoveWindow(hwnd, 150, 150, 768, 768, True)

# 指定句柄设置为前台,也就是激活
win32gui.SetForegroundWindow(hwnd)
# 设置为后台
win32gui.SetBkMode(hwnd, win32con.TRANSPARENT)

コード例 #6
0
def qq_windows(title):
    handle = win32gui.FindWindow(None, title)
    win32gui.SetForegroundWindow(handle)
    time.sleep(0.5)
コード例 #7
0
ファイル: helper.py プロジェクト: Trafire/autof2
def drag_window():
    win32gui.ShowWindow(window.f2_hwnd, win32con.SW_MAXIMIZE)
    win32gui.SetForegroundWindow(window.f2_hwnd)
    c = window.get_corners(window.f2_hwnd)
    mouse.click_and_drag(c[0] + 25, c[1] + 50, c[2] - 25, c[3] - 50)
コード例 #8
0
def set_foreground(hwnd):
    win32gui.SetForegroundWindow(hwnd)
コード例 #9
0
    '#js-album-opbar-container > div.mod-tool-op > div:nth-child(1) > a'
).click()
driver.switch_to.parent_frame()
time.sleep(15)

# 手动点击'上传图片按钮'

uploadwindowname = u'打开'  # CHROME窗口名称是打开
uploadwindow = win32gui.FindWindow('#32770', uploadwindowname)  # 定位“文件上传 窗口
print uploadwindow
# 最后输出,如果输出0说明定位失败了
parent = win32gui.FindWindowEx(uploadwindow, None, 'ComboBoxEx32', None)
Combobox_real = win32gui.FindWindowEx(parent, None, 'ComboBox', None)
Edit_box = win32gui.FindWindowEx(Combobox_real, None, 'Edit', None)
# 这段代码是先定位到最上层的父窗口,再逐层定位到输入框(chrome于FF有所不同,FF下可以直接定位)
win32gui.SetForegroundWindow(Edit_box)
time.sleep(1)
win32gui.SendMessage(Edit_box, win32con.WM_SETTEXT, None,
                     r'1.jpg')  # 自己电脑的默认路径下是D盘
openbuttonname = u'打开(&O)'
time.sleep(1)
openbutton = win32gui.FindWindowEx(uploadwindow, None, "Button",
                                   openbuttonname)  # 定位“保存”按钮
print openbutton
win32gui.PostMessage(openbutton, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON,
                     0)
win32gui.PostMessage(openbutton, win32con.WM_LBUTTONUP, win32con.MK_LBUTTON, 0)
#
# dialog = win32gui.FindWindow('#32770', None)
# print dialog
#
コード例 #10
0
def save_evidence1(self, screen_shot_name):

    save_screenshot(self, screen_shot_name)

    # 如果是第一次保留留痕,需要创建excel文件
    evidence_file = file_path + "\\test_evidence.xls"
    if not os.path.exists(evidence_file):

        workbook = xlwt.Workbook(encoding='utf-8')  # 新建工作簿
        sheet1 = workbook.add_sheet("evidence")  # 这里应该是用例名称
        workbook.save(evidence_file)  # 保存
        # 打开截图留痕excel
        win32api.ShellExecute(0, 'open', evidence_file, '', '', 1)
        # 等待excel打开,等待时间是不是有点长
        sleep(10)
        # 获得excel临时文件的句柄
        # handle = win32gui.FindWindow("XLMAIN", "Microsoft Excel - test_evidence.xls  [互換モード]")
        handle = win32gui.FindWindow("XLMAIN",
                                     "Microsoft Excel - test_evidence.xls")
        # 激活并显示窗口。
        win32gui.ShowWindow(handle, win32con.SW_MAXIMIZE)
        win32gui.EnableWindow(handle, True)
        win32gui.SetForegroundWindow(handle)
        # 获取最下方缩小excel的图标,并缩小至70%
        sleep(1)
        # 设置输入法为英文
        set_EN()
        pyautogui.moveTo(1311, 848)
        sleep(1)
        pyautogui.click()
        pyautogui.click()
        pyautogui.click()
        sleep(1)
        first_save_evidence = 1

    # 如果是第二次留痕
    else:
        sleep(1)
        # 获得excel临时文件的句柄
        handle = win32gui.FindWindow("XLMAIN",
                                     "Microsoft Excel - test_evidence.xls")
        # 激活并显示窗口。
        win32gui.ShowWindow(handle, win32con.SW_MAXIMIZE)
        win32gui.EnableWindow(handle, True)
        win32gui.SetForegroundWindow(handle)
    sleep(2)
    # 点击插入图片,并插入截图好的evidence图片
    pyautogui.keyDown('Alt')
    pyautogui.keyDown("I")
    pyautogui.keyUp('Alt')
    pyautogui.keyUp("I")
    pyautogui.press('P')
    pyautogui.press('F')
    # 鼠标移动到文件路径位置
    time.sleep(2)

    for i in range(0, 6):
        pyautogui.press("Tab")
    sleep(1)
    pyautogui.press("space")
    insert_file_path = file_path
    pyautogui.typewrite(insert_file_path)

    time.sleep(1)
    pyautogui.press('enter')
    for i in range(0, 5):
        pyautogui.press("Tab")
    sleep(1)
    insert_file_name = filename + ".png"
    pyautogui.typewrite(insert_file_name)
    time.sleep(1)
    pyautogui.press('enter')
    sleep(1)

    # 鼠标移动到excel下移图标位置,并移动至空白行,为下一次插入图片的位置做准备
    pyautogui.moveTo(1427, 814)
    for i in range(0, 47):
        pyautogui.click()
    sleep(5)

    # 鼠标移动到excel的初始插入位置
    x, y = 35, 186
    pyautogui.moveTo(x, y)
    pyautogui.click()
    time.sleep(1)

    # 使excel成为disableWindow
    win32gui.ShowWindow(handle, win32con.SW_MINIMIZE)
    win32gui.EnableWindow(handle, False)
コード例 #11
0
def save_evidence(self, screen_shot_name):

    save_screenshot(self, screen_shot_name)

    # 如果是第一次保留留痕,需要创建excel文件
    evidence_file = suite_path + "\\" + suite_name + "\\test_evidence.xlsx"
    if not os.path.exists(evidence_file):
        global wb
        wb = Workbook()
        sheet_name = get_func_name()
        ws = wb.create_sheet(sheet_name, 0)
        # wb.remove("sheet")
        # ws = wb[sheet_name]
        wb.save(evidence_file)
        wb.close()

        # global workboo
        # workbook = xlwt.Workbook(encoding='utf-8')  # 新建工作簿
        # sheet_name = get_func_name()
        # sheet1 = workbook.add_sheet(sheet_name)  # 这里应该是用例名称
        # # sheet = workbook.add_sheet("evidence")  # 这里应该是用例名称
        # workbook.save(evidence_file)  # 保存

        # 打开截图留痕excel
        win32api.ShellExecute(0, 'open', evidence_file, '', '', 1)
        # 等待excel打开,等待时间是不是有点长
        sleep(10)
        # 获得excel临时文件的句柄
        # handle = win32gui.FindWindow("XLMAIN", "Microsoft Excel - test_evidence.xlsx [互換モード]")
        handle = win32gui.FindWindow("XLMAIN",
                                     "Microsoft Excel - test_evidence.xlsx")
        # 激活并显示窗口。
        win32gui.ShowWindow(handle, win32con.SW_MAXIMIZE)
        win32gui.EnableWindow(handle, True)
        win32gui.SetForegroundWindow(handle)
        # 获取最下方缩小excel的图标,并缩小至70%
        sleep(1)
        # 设置输入法为英文
        set_EN()
        pyautogui.moveTo(1311, 848)
        sleep(1)
        pyautogui.click()
        pyautogui.click()
        pyautogui.click()
        sleep(1)
        first_save_evidence = 1

    # 如果是第二次留痕
    else:
        sleep(1)
        # 获得excel临时文件的句柄
        # wb = load_workbook(evidence_file)
        # print("evidence_file",evidence_file)

        # wb = win32api.ShellExecute(0, 'open', evidence_file, '', '', 1)
        # sleep(5)
        # sheet_name = get_func_name()
        # # ws = wb.create_sheet(sheet_name)sleep(10)
        # # 		sheet_name = get_func_name()
        # # wb.save(evidence_file)
        # # print("666")
        # with pd.ExcelWriter(evidence_file) as writer:
        # 	data = "1"
        # 	data.to_excel(writer, sheet_name=sheet_name)

        handle = win32gui.FindWindow("XLMAIN",
                                     "Microsoft Excel - test_evidence.xlsx")
        # 激活并显示窗口。
        win32gui.ShowWindow(handle, win32con.SW_MAXIMIZE)
        win32gui.EnableWindow(handle, True)
        win32gui.SetForegroundWindow(handle)

        # sheet_name = get_func_name()
        # print("2workbook", workbook)
        # print("2sheet_name", sheet_name)
        # sleep(2)
        # sheet2 = workbook.add_sheet(sheet_name)  # 这里应该是用例名称
        # # ws1 = workbook.create_sheet("Mysheet")
        # #sheet2 = workbook.add_sheet(sheet_name)  # 这里应该是用例名称
        # #workbook.save(evidence_file)  # 保存
        sleep(2)

    sleep(2)
    # 点击插入图片,并插入截图好的evidence图片
    pyautogui.keyDown('Alt')
    pyautogui.keyDown("I")
    pyautogui.keyUp('Alt')
    pyautogui.keyUp("I")
    pyautogui.press('P')
    pyautogui.press('F')
    # 通过tab选中文件
    time.sleep(2)

    for i in range(0, 6):
        pyautogui.press("Tab")
        sleep(0.5)
    sleep(1)
    pyautogui.press("space")
    insert_file_path = suite_path + "\\" + suite_name
    pyautogui.typewrite(insert_file_path)
    sleep(1)
    pyautogui.press('enter')

    sleep(2)
    for i in range(0, 5):
        pyautogui.press("Tab")
        sleep(0.5)
    sleep(1)
    insert_file_name = screenshot_name + ".png"
    pyautogui.typewrite(insert_file_name)
    time.sleep(1)
    pyautogui.press('enter')
    sleep(1)

    # 鼠标移动到excel下移图标位置,并移动至空白行,为下一次插入图片的位置做准备
    pyautogui.moveTo(1427, 814)
    for i in range(0, 47):
        pyautogui.click()
    sleep(5)

    # 鼠标移动到excel的初始插入位置
    x, y = 35, 186
    pyautogui.moveTo(x, y)
    pyautogui.click()
    time.sleep(1)

    # 使excel成为disableWindow
    win32gui.ShowWindow(handle, win32con.SW_MINIMIZE)
    win32gui.EnableWindow(handle, False)
コード例 #12
0
ファイル: MapleBotV3.py プロジェクト: zchen44/AriesJr
def record(hwnd = None, map = None):
	if not hwnd:
		hwnd=win32gui.GetDesktopWindow()

	l,t,r,b=win32gui.GetWindowRect(hwnd)
	h=b-t
	w=r-l
	mon = {'top': t, 'left': l, 'width': 10, 'height': 10}

	#pos_start = (0,0)

	win32gui.SetForegroundWindow(hwnd)
	time.sleep(.2) #lame way to allow screen to draw before taking shot

	purple = np.array(COLORS['purple'], dtype = "uint8")
	yellow_inner = np.array(COLORS['yellow_inner'], dtype = "uint8")
	yellow_outer = np.array(COLORS['yellow_outer'], dtype = "uint8")
	outer_green = np.array(COLORS['outer_green'], dtype = "uint8")
	inner_green = np.array(COLORS['inner_green'], dtype = "uint8")
	corner_green = np.array(COLORS['corner_green'], dtype = "uint8")

	sct = mss()
	prev = '' #defaults at ab6
	while(1):

		if Status.script_type == 'h':
			Status.mp_farm_flag = True
			Status.map = 'max_mp'
		##if Status.mp_farm_flag:
		#if Status.stage == 1:
		#	Status.map = 's1'
		#elif Status.stage == 2:
		#	Status.map = 's2'
		#elif Status.stage == 3:
		#	Status.map = 's3'
		#elif Status.stage == 4:
		#	Status.map = 's4'
		#elif Status.stage == 5:
		#	Status.map = 's5'
		#elif Status.stage == 6:
		#	Status.map = 's6'
		#else:
		#	Status.map = 'mp'

		#Grabs the dimensions of the minimap if it changes
		if prev != Status.map:
			prev = Status.map
			dimensions = MAPS[Status.map] # list where [top, left, width, height] is recorded
			mon = {'top': t + dimensions[0], 'left': l + dimensions[1], 'width': dimensions[2], 'height': dimensions[3]}

		img = np.array(sct.grab(mon))

		mask1 = cv2.inRange(img, purple, purple)
		y,x = np.where(mask1 == 255)
		if (x.size != 0):
			Status.rune_flag = True
			Status.rune_coord = tuple(zip(x,y))
			#center coordinate of rune
			Status.rune_center = (int(np.mean(x)), int(np.mean(y)))
		else:
			Status.rune_flag = False
			Status.rune_center = ()
			Status.rune_coord = ()

		mask2 = cv2.inRange(img, yellow_inner, yellow_inner)
		mask3 = cv2.inRange(img, yellow_outer, yellow_outer)
		cy, cx = np.where(mask3 == 255) #changed so it reflects x and y axis. Default is len by width so y by x originally.
		#case where character center is detected
		if (cx.size != 0):
			Status.character_coord = tuple(zip(cx,cy))
			#center coordinate of character
			Status.character_center = (int(np.mean(cx)), int(np.mean(cy)))
		#case when not so used when character changes maps
		elif (cx.size == 0) and (Status.character_center != (-1,-1)):
			Status.character_center = (-1,-1)
			Status.stage = (Status.stage + 1) % 7

		#print("Character center: " + str(Status.character_center))
		#if (Status.character_center)
		
		mask4 = cv2.inRange(img, outer_green, outer_green)
		mask5 = cv2.inRange(img, corner_green, corner_green)
		mask6 = cv2.inRange(img, inner_green, inner_green)
		npcy, npcx = np.where(mask6 == 255) 
		if (npcx.size != 0):
			Status.character_coord = tuple(zip(npcx,npcy))
			#center coordinate of NPCs (used as map identifier)
			Status.npc_center = (int(np.mean(npcx)), int(np.mean(npcy)))

		final_mask = cv2.bitwise_or(mask1,mask2)
		final_mask = cv2.bitwise_or(final_mask,mask3)
		final_mask = cv2.bitwise_or(final_mask,mask4)
		final_mask = cv2.bitwise_or(final_mask,mask5)
		final_mask = cv2.bitwise_or(final_mask,mask6)
		result = cv2.bitwise_and(img, img, mask = final_mask)

		cv2.imshow('minimap + mask', np.hstack([img, result]))
		if cv2.waitKey(25) & 0xFF == ord('q'):
			cv2.destroyAllWindows()
			break
コード例 #13
0
ファイル: window.py プロジェクト: Rektedekte/MSSolver
 def restore(self):
     shell = win32com.client.Dispatch("WScript.Shell")
     shell.SendKeys('%')
     win32gui.ShowWindow(self.hwnd, win32con.SW_RESTORE)
     win32gui.SetForegroundWindow(self.hwnd)
コード例 #14
0
输入3,进入单题收集
输入p,进入整章收集
输入a,进入发广告模式
输入q,离开

Enter choice:"""

try:
    choice = raw_input(choice).strip()[0].lower()
except (EOFError, KeyboardInterrupt):
    choice = 'q'
if choice == 'q': exit()

win32gui.ShowWindow(getbrow, win32con.SW_RESTORE)  ##强行显示界面
win32gui.ShowWindow(getbrow, win32con.SW_MAXIMIZE)  ##窗口最大化
win32gui.SetForegroundWindow(getbrow)
##    win32gui.SetWindowPos(getbrow,win32con.HWND_TOPMOST,0,0,
##                          win32con.SWP_NOSIZE,win32con.SWP_NOSIZE,
##                          win32con.SWP_NOZORDER)           ##将浏览器窗口提到最前
##    win32gui.SetForegroundWindow(getbrow)            ##强行显示界面
time.sleep(0.8)  #等待窗口完全彈出

##if choice == '1':AutoAnswer()
##if choice == '2':Pickit()
##if choice == '3':OnePickit()
##if choice == 'p':SemiautoPick()
##if choice == 'a':AutoAD()

chos = {
    '1': AutoAnswer,
    '2': Pickit,
コード例 #15
0
def SetForegroundWindow(hwd):
    win32gui.SetForegroundWindow(hwd._as_parameter_)
コード例 #16
0
#coding=utf-8
#Introduction:自動答題 ----- for:闯关王——挑战场,正式可用,20140906
#version:Autoanswer_v1.1
#updata v1.0:修改鼠標模擬的方式,解決鼠標失控問題(側面解決死循環)
#updata 0.1:基於Autoanswer_a1.0的改寫
from PIL import Image,ImageGrab
import os,time
import hashlib,pickle
import win32gui,win32con,win32api

getbrow = win32gui.FindWindow('Chrome_WidgetWin_1',u'立秋·驾培-闯关王 - Google Chrome')            ##定义窗口
win32gui.ShowWindow(getbrow,win32con.SW_RESTORE)            ##强行显示界面
win32gui.ShowWindow(getbrow,win32con.SW_MAXIMIZE)           ##窗口最大化
win32gui.SetForegroundWindow(getbrow)           ##将浏览器窗口提到最前
time.sleep(0.8)         #等待窗口完全彈出

#檢查工作目錄
if os.path.isdir('tmp'):
    pass
else:
    os.mkdir('tmp')

    #定義元素
Pcmd5 = '38E53A7D5DD9FC87B8C74B6CD911C22D'

Qbox = (515,470,1020,488)
Q2box = (860,500,1050,655)
Abox = (510,564,840,586)
Bbox = (510,590,840,612)
Cbox = (510,617,840,639)
Dbox = (510,644,840,666)
コード例 #17
0
def _prompt_enum_handle(hwnd, title):
    if win32gui.GetWindowText(hwnd) == title and win32gui.GetClassName(hwnd) == "#32770":
        # https://stackoverflow.com/a/30314197/5458478
        # ¯\_(ツ)_/¯
        win32com.client.Dispatch("WScript.Shell").SendKeys('%')
        win32gui.SetForegroundWindow(hwnd)
コード例 #18
0
ファイル: testconfirm.py プロジェクト: aboutxyz/win32
from constant import *
import concurrent.futures
  
def find_idxSubHandle(pHandle, winClass, index=0):
    """已知子窗口的窗体类名 寻找第index号个同类型的兄弟窗口"""
    assert type(index) == int and index >= 0
    handle = win32gui.FindWindowEx(pHandle, 0, winClass, None)
    while index > 0:
        handle = win32gui.FindWindowEx(pHandle, handle, winClass, None)
        index -= 1
    return handle

docuwindow = win32gui.FindWindow('WindowsForms10.Window.8.app.0.3b93019_r11_ad1','Document ApplicationNBZRP0')
backwindow = win32gui.FindWindowEx(docuwindow,0,'WindowsForms10.MDICLIENT.app.0.3b93019_r11_ad1',None)
bookingwindow = win32gui.FindWindowEx(backwindow,0,'WindowsForms10.Window.8.app.0.3b93019_r11_ad1','Accept E-booking')
win32gui.SetForegroundWindow(docuwindow)
bookingtitle = find_idxSubHandle(bookingwindow,'WindowsForms10.Window.8.app.0.3b93019_r11_ad1',4)
retrieve = win32gui.FindWindowEx(bookingtitle,0,'WindowsForms10.BUTTON.app.0.3b93019_r11_ad1','Retrieve')
showdeail = find_idxSubHandle(bookingtitle, 'WindowsForms10.BUTTON.app.0.3b93019_r11_ad1',1)
def confirmfunc():
    confirmwindow = find_idxSubHandle(bookingwindow, 'WindowsForms10.Window.8.app.0.3b93019_r11_ad1',0)
    repending = find_idxSubHandle(confirmwindow, 'WindowsForms10.Window.b.app.0.3b93019_r11_ad1',1)
    try:
        win32gui.PostMessage(repending,win32con.WM_LBUTTONDOWN,None,None)
        win32gui.PostMessage(repending,win32con.WM_LBUTTONUP,None,None)
        time.sleep(3)  
    finally:
        aa = win32gui.FindWindow('#32770','Warning')
        while aa:
            shi = find_idxSubHandle(aa,'Button',1)
            win32gui.PostMessage(shi, win32con.WM_KEYDOWN, win32con.VK_RETURN, 0)
コード例 #19
0
ファイル: printset2.py プロジェクト: OuSatoru/Teller
def onKeyboardEvent(event):
    HWND = win32gui.GetForegroundWindow()
    tt = win32gui.GetWindowText(HWND)

    if tt.find(FORE_TITLE) > -1:
        if event.Key == 'Rcontrol':
            global a
            a += 1
            print a
            if a < len(csvs):
                local = ''
                a_person = people(csvs[a].rstrip())
                print a_person.name + a_person.idnum + a_person.phone
                time.sleep(0.5)
                win32gui.SendMessage(ID_hwnd, win32con.WM_LBUTTONDOWN, 0, 0)
                time.sleep(0.01)
                win32gui.SendMessage(ID_hwnd, win32con.WM_LBUTTONUP, 0, 0)
                win32gui.SendMessage(ID_hwnd, win32con.WM_SETTEXT, None,
                                     a_person.idnum)
                time.sleep(0.35)
                win32gui.PostMessage(ID_hwnd, win32con.WM_KEYDOWN,
                                     win32con.VK_RETURN, None)
                time.sleep(0.03)

                if len(a_person.phone) == 11:
                    typer('101013')
                    press('enter', 'caps_lock', 'a', '0')
                    typer(a_person.idnum)
                    press('0', 'enter', 'enter')
                    typer('21000101')
                    if a_person.gender == 1:
                        press('1')
                        typer(a_person.birthdate)
                        press('m', 'r', 'enter')
                    else:
                        press('2')
                        typer(a_person.birthdate)
                        press('m', 's', 'enter')
                    typer('2015601561')
                    typer(a_person.phone)
                    typer('000644')

                    if win32gui.FindWindow(None, u'输入身份证号码') > 0:
                        cant = win32gui.FindWindow(None, u'输入身份证号码')
                        print 'cant' + hex(cant)
                        time.sleep(0.01)
                        qd = win32gui.FindWindowEx(cant, None, 'Button', None)
                        time.sleep(0.03)
                        win32gui.SendMessage(qd, win32con.BM_CLICK, 0, -1)
                        time.sleep(0.02)
                        win32gui.SendMessage(tID_hwnd, win32con.WM_SETTEXT,
                                             None, a_person.idnum)
                        time.sleep(0.01)
                        win32gui.SendMessage(tName_hwnd, win32con.WM_SETTEXT,
                                             None, a_person.name)
                        time.sleep(0.02)

                        win32gui.SendMessage(tAdd_hwnd,
                                             win32con.WM_LBUTTONDOWN, 0, 0)
                        time.sleep(0.01)
                        win32gui.SendMessage(tAdd_hwnd, win32con.WM_LBUTTONUP,
                                             0, 0)
                        time.sleep(0.02)
                        win32gui.PostMessage(tAdd_hwnd, win32con.WM_KEYDOWN,
                                             win32con.VK_RETURN, None)
                        time.sleep(0.01)
                        win32gui.PostMessage(tAdd_hwnd, win32con.WM_KEYUP,
                                             win32con.VK_RETURN, None)

                        #win32gui.SendMessage(tAdd_hwnd, win32con.BM_CLICK, 0, -1)
                        time.sleep(0.01)
                        local = u'东台市安丰镇'

                    print 'start enter'
                    press('enter', 'enter')
                    typer('224200')
                    press('caps_lock')

                    print 'first is ' + local
                    if local != u'东台市安丰镇':
                        print 'no'
                        local = win32gui.GetWindowText(location_hwnd)
                        local = local.strip()
                        print '2nd is ' + local

                        print 'here'
                        print local
                        for one in local:
                            win32gui.PostMessage(HWND, win32con.WM_CHAR,
                                                 ord(one), 0)
                    else:
                        local = u'江苏省东台市安丰镇'
                        local = local.strip().encode('gb2312')
                        for one in local:
                            win32gui.PostMessage(HWND, win32con.WM_CHAR,
                                                 ord(one), 0)

                    press_over_time('enter', 4)
                    typer('320919011351258147')
                    time.sleep(0.1)

                    win32gui.SendMessage(print_hwnd, win32con.WM_LBUTTONDOWN,
                                         0, 0)
                    time.sleep(0.01)
                    win32gui.SendMessage(print_hwnd, win32con.WM_LBUTTONUP, 0,
                                         0)
                    time.sleep(0.02)
                    win32gui.PostMessage(print_hwnd, win32con.WM_KEYDOWN,
                                         win32con.VK_RETURN, None)
                    time.sleep(0.01)
                    win32gui.PostMessage(print_hwnd, win32con.WM_KEYUP,
                                         win32con.VK_RETURN, None)
                    #time.sleep(0.01)
                    #win32gui.SendMessage(print_hwnd, win32con.BM_CLICK, 0, -1)
                elif len(a_person.phone) == 8:
                    type_phone(a_person, HWND)
                else:
                    type_none(a_person, HWND)
                #press('enter','enter')
            #print a_person.location

        elif event.Key == 'Rshift':
            time.sleep(0.05)
            HWND = win32gui.FindWindow(u'昇騰Telnet', None)
            time.sleep(0.01)
            win32gui.SetForegroundWindow(HWND)
        '''elif event.Key == 'Rshift':
            print a
            print '91043'
            if a < len(csvs):
                a_person = people(csvs[a])
                time.sleep(0.8)
                typer('91043a')
                #press('enter','caps_lock','a','0')
                typer(a_person.idnum)
                #press('0','enter','enter')
                #typer('21000101')
                
                
                press_over_time('enter',11)
                typer(a_person.card)
                press_over_time('enter',5)
                
                typer('ynyn')'''
    return True
コード例 #20
0
tf_p = "DIM SELECT.txt"


def windowEnumerationHandler(hwnd, top_windows):
    top_windows.append((hwnd, win32gui.GetWindowText(hwnd)))


if __name__ == "__main__":
    results = []
    top_windows = []
    win32gui.EnumWindows(windowEnumerationHandler, top_windows)
    for i in top_windows:
        if "creo parametric" in i[1].lower():
            print(i)
            win32gui.ShowWindow(i[0], 5)
            win32gui.SetForegroundWindow(i[0])
            break
keyboard.press_and_release('alt+f')
time.sleep(1)
keyboard.press_and_release('m')
time.sleep(1)
keyboard.press_and_release('t')
time.sleep(1)
pyperclip.copy(tf_p)
keyboard.press_and_release('ctrl+v')
keyboard.press_and_release('enter')
time.sleep(2)
keyboard.press_and_release('left')
keyboard.press_and_release('right')
keyboard.press_and_release('right')
keyboard.press_and_release('down')
コード例 #21
0
ファイル: winmine_util.py プロジェクト: bnfour/winmine_ai
def topwindow(handle):
    win32gui.SetForegroundWindow(handle)
コード例 #22
0
names = []

while True:
    pacthHandle = win32gui.FindWindow('TdxW_MainFrame_Class', None)
    if pacthHandle == 0:
        break
    title = win32gui.GetWindowText(pacthHandle)
    result = title.replace(']', '').split('-')
    name = result[2]
    if names.count(name) == 0:
        names.append(name)
    elif names.count(name) == 1:
        break
    print(names)

    win32gui.SetForegroundWindow(pacthHandle)
    time.sleep(.1)
    KeyBoard.key_input_key('page_down')
    time.sleep(.1)

print(names)

# pacthHandle = win32gui.FindWindow('TdxW_MainFrame_Class', None)
# win32gui.SetForegroundWindow(pacthHandle)
# print('pacthhandle %d'%pacthHandle)
# title = win32gui.GetWindowText(pacthHandle)
# clsname = win32gui.GetClassName(pacthHandle)
# print(clsname, title)

# childs = []
# childs = get_child_windows(pacthHandle)
コード例 #23
0
 def set_foreground(self):
     """Get the focus on the desired open window"""
     win32gui.SetForegroundWindow(self._handle)
コード例 #24
0
def run():
    win32gui.SetForegroundWindow(global_configs.hwnd)
    time.sleep(global_configs.Alberta_inner_wait_time)
    # compare image to know whether to use F11 or not
    # TODO: Add function to compare
    # mouse move to the top
    # TODO: Move mouse to the top

    # Click to throw
    MouseAction.left_long_click(200, 200,
                                global_configs.Alberta_floating_throwing_time)
    # Wait a few seconds
    time.sleep(global_configs.Alberta_floating_after_throwing_waiting_time)
    # Limited the fishing line
    MouseAction.left_long_click(
        200, 200, global_configs.Alberta_floating_straining_line_time)

    x = global_configs.windows_x
    y = global_configs.windows_y

    # Check if suitable for the line to fish
    # Too easy to throw more than 10m
    too_far_flag = True
    while too_far_flag:
        maxes = 0
        index = 0
        for i in range(0, 3):
            image = take_screenshot_of_desktop_using_PIL(
                window_x=x,
                window_y=y,
                relative_crop_box=(1031, 652, 1031 + 34, 652 + 49))
            grey_image = rgb2grey(image)
            diff_list = [
                image_diff(grey_image,
                           global_configs.digit_0_image,
                           function="phash"),
                image_diff(grey_image,
                           global_configs.digit_1_image,
                           function="phash"),
                image_diff(grey_image,
                           global_configs.digit_2_image,
                           function="phash"),
                image_diff(grey_image,
                           global_configs.digit_3_image,
                           function="phash"),
                image_diff(grey_image,
                           global_configs.digit_4_image,
                           function="phash"),
                image_diff(grey_image,
                           global_configs.digit_5_image,
                           function="phash"),
                image_diff(grey_image,
                           global_configs.digit_6_image,
                           function="phash"),
                image_diff(grey_image,
                           global_configs.digit_7_image,
                           function="phash"),
                image_diff(grey_image,
                           global_configs.digit_8_image,
                           function="phash"),
                image_diff(grey_image,
                           global_configs.digit_9_image,
                           function="phash")
            ]
            logger.info("{}th Compare meter digit result:{}".format(
                i + 1, diff_list))
            for k in range(0, len(diff_list)):
                if diff_list[k] > maxes:
                    index = k
                    maxes = diff_list[k]
        if maxes < 0.7:
            logger.debug("Seems be water, no meter indicator found.")
            continue
        else:
            logger.info("Meter: {}, possibility:{}".format(index, maxes))

        if index < 6 and index != 1:
            # Meter not good ,release
            MouseAction.left_long_click(200, 200, 4)
            time.sleep(5)
            too_far_flag = False
            return
        elif index == 8:
            # A little long
            MouseAction.left_long_click(200, 200, 0.2)
            too_far_flag = False
            time.sleep(1)
        elif index == 9:
            # More longer
            MouseAction.left_long_click(200, 200, 0.5)
            too_far_flag = False
            time.sleep(1)
        elif index == 1:
            MouseAction.left_long_click(200, 200, 1)
            time.sleep(1)
        elif index == 7 or index == 6:
            # perfect
            too_far_flag = False

    # jump flag
    jump_flag = False

    max_time = global_configs.Alberta_max_waiting_time / 0.2
    # Waiting the fish to get in
    while max_time > 0:

        # Get the image of the wheel
        image = take_screenshot_of_desktop_using_PIL(
            window_x=x, window_y=y, relative_crop_box=(1214, 560, 1238, 566))

        # Compare with the blue line
        d = image_diff(image, global_configs.wheel_image)
        # logger.debug("Image diff result for wheel:{}.".format(d))
        if d > 0.5:

            # Lift the rod
            logger.debug("Catch fish.")
            MouseAction.hold_on_right_then_left(
                200,
                200,
                right_hold_time=global_configs.Alberta_floating_lift_rod_time,
                both_hold_time=global_configs.Alberta_floating_lift_fish_time)
            logger.info("Catch fish finish.")
            break
        else:
            time.sleep(0.2)
            max_time -= 1

    # Wait for too long, abandon this fish rod
    if max_time == 0:
        logger.info("Too long time pass, re-throw the rod.")
        MouseAction.left_long_click(200, 200, 6)
        return

    # Check if success
    time.sleep(8)
    logger.info("Check the result.")

    image = take_screenshot_of_desktop_using_PIL(window_x=x,
                                                 window_y=y,
                                                 relative_crop_box=(670, 633,
                                                                    670 + 160,
                                                                    633 + 40))

    d = image_diff(global_configs.get_image, image)
    if d > 0.5:

        # Catch the fish
        time.sleep(3)
        logger.debug("Image diff result for catch:{}.".format(d))
        logger.debug("Set cursor in {}, {}.".format(x + 700, y + 650))
        MouseAction.click_with_delay(x + 700, y + 650)
        logger.debug("Finish click.")
    else:

        # The fish caught but full
        f = image_diff(global_configs.full_image, image)
        logger.debug("Image diff result for full:{}.".format(f))
        if f > 0.5:
            logger.info("Full! Jump time.")
            jump_flag = True
            logger.debug("Set cursor in {}, {}.".format(x + 570, y + 650))
            MouseAction.click_with_delay(x + 570, y + 650)
            logger.debug("Finish click.")
            time.sleep(4)
        # else:
        #     logger.debug("Await for command.")
        #     sys.exit(1)

    # Check special event
    time.sleep(4)
    image = take_screenshot_of_desktop_using_PIL(window_x=x,
                                                 window_y=y,
                                                 relative_crop_box=(257, 527,
                                                                    257 + 200,
                                                                    527 + 50))
    f = image_diff(global_configs.special_event_image, image)
    logger.debug("Image diff result for special events:{}.".format(f))
    if f > 0.5:
        # Have special event
        logger.info("Trigger special event.")
        logger.debug("Set cursor in {}, {}.".format(x + 350, y + 550))
        MouseAction.click_with_delay(x + 350, y + 550)
        logger.debug("Finish click.")
        time.sleep(4)
    else:
        logger.info("No special event.")

    # Check level up event
    image = take_screenshot_of_desktop_using_PIL(window_x=x,
                                                 window_y=y,
                                                 relative_crop_box=(355, 616,
                                                                    355 + 200,
                                                                    616 + 50))
    f = image_diff(global_configs.special_event_image, image)
    logger.debug("Image diff result for special events:{}.".format(f))
    if f > 0.7:
        logger.info("Trigger level UP.")
        # Have special event
        logger.debug("Set cursor in {}, {}.".format(x + 425, y + 640))
        MouseAction.click_with_delay(x + 425, y + 640)
        logger.debug("Finish click.")
        time.sleep(4)
    else:
        logger.info("Continue level.")

    # Jump time
    if jump_flag:
        logger.info("Jump time start.")
        KeyboardAction.press_and_release(0x54)
        logger.info("Press T.")
        time.sleep(2)
        logger.debug("Set cursor in {}, {}.".format(x + 650, y + 530))
        MouseAction.click_with_delay(x + 650, y + 530)
        logger.debug("Finish click.")
        logger.info("Click center.")
        time.sleep(2)
        logger.debug("Set cursor in {}, {}.".format(x + 525, y + 485))
        MouseAction.click_with_delay(x + 525, y + 485)
        logger.debug("Finish click.")
        logger.info("Click continue.")
        time.sleep(2)
        logger.debug("Set cursor in {}, {}.".format(x + 600, y + 600))
        MouseAction.click_with_delay(x + 600, y + 600)
        logger.debug("Finish click.")
        logger.info("Click confirm button.")
        time.sleep(5)
        logger.info("Continue Fishing.")
        jump_flag = False
コード例 #25
0
 def set_foreground(self):
     #put the window in the foreground
     win32gui.SetForegroundWindow(self._handle)
コード例 #26
0
ファイル: NIFTI_T2map.py プロジェクト: bfoe/BrukerOfflineReco
    else: nointerpolation = False
    if '--nofiltering' in argDict: nofiltering = True
    else: nofiltering = False

    if InputFile == "":
        #intercatively choose input NIFTI file
        InputFile = askopenfilename(title="Choose NIFTI file",
                                    filetypes=[("NIFTI files",
                                                ('MAGNT.nii.gz'))])
        if InputFile == "":
            print('ERROR: No input file specified')
            sys.exit(2)
        InputFile = os.path.abspath(InputFile)
        TKwindows.update()
        try:
            win32gui.SetForegroundWindow(win32console.GetConsoleWindow())
        except:
            pass  #silent
    dirname = os.path.dirname(InputFile)
    basename = os.path.basename(InputFile)
    basename = os.path.splitext(basename)[0]
    basename = basename[0:basename.rfind('_MAG')]
    outfile1 = basename + '_T2map.nii.gz'
    outfile2 = basename + '_R2map.nii.gz'
    outfile3 = basename + '_TE0map.nii.gz'

    print('Reading NIFTI file')
    sys.stdout.flush()
    img = nib.load(InputFile)
    IMGdata = img.get_data().astype(np.float32)
    SpatResol = np.asarray(img.header.get_zooms())
コード例 #27
0
 def jump_window(self):
     # 跳转到游戏窗口
     win32gui.SetForegroundWindow(self.hwnd)
     win32gui.PostMessage(self.hwnd, win32con.WM_SYSCOMMAND,
                          win32con.SC_RESTORE, 0)
コード例 #28
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 >= 6000:
                # 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)
        if os.path.basename(__file__) == 'console_surface.py':
            win32gui.MoveWindow(bt_window, 0, 0, 1280, 820, 1)
            bt_rec = win32gui.GetWindowRect(bt_window)
        else:
            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:
            if os.path.basename(__file__) == 'console_surface.py':
                found = pyautogui.locateCenterOnScreen(hs_png,
                                                       region=(10, 380, 300,
コード例 #29
0
import sys
import timeit
import math

pyautogui.PAUSE = 1.5
pyautogui.FAILSAFE = True  #moving mouse to upper left corner will stop pyautogui
pyautogui.MINUMUM_DURATION = 0.1
pyautogui.MAXIMUM_DURATION = 1.5
print("your screen res is %sx%s" % (pyautogui.size()[0], pyautogui.size()[1]))
print("IMPORTANT: DO NOT Minimize MapleStory 2 window")
#TODO: set different mouse cordinates for different screen res

window_name = "Untitled - Paint"
whnd = win32gui.FindWindowEx(None, None, None, window_name)
if (whnd != 0):
    win32gui.SetForegroundWindow(whnd)
    print("FOUND")
    #TODO: work around if MapleStory window is Minimized
else:
    print("NOPE")

for i in list(range(2))[::-1]:
    print(i + 1)
    time.sleep(1)

i = 0
while i < 5:
    print(pyautogui.position())
    # while:
    #1st click(1750,239) From starting position to upper platform
    start = timeit.default_timer()
コード例 #30
0
 def SetAsForegroundWindow(self):
     # First, make sure all (other) always-on-top windows are hidden.
     self.hide_always_on_top_windows()
     win32gui.SetForegroundWindow(self._hwnd)