async def alipay_buy(pa, pw_file='130_pw.txt'): tb = taobao_trade from qgb import Win if not pa: return pa await pa.bringToFront() Win.set_foreground(title='支付宝 - 网上支付 安全快速! - Cent Browser') # x,y=await tb.get_abs_xy(pa,'label[class=ui-label]')#(x+222,y+5) x, y = await tb.get_abs_xy(pa, 'a[seed="sc_edit_forgetPwd"]') #(x-180,y+5) s, [x, y] = await tb.press_keys(pa, F.read(pw_file), xy=(x - 160, y + 5)) await A.sleep(0.6) #sec Win.click(x, y + 67) return pa
async def press_keys(page, *s, xy=(None, None)): from qgb import Win if len(s) == 1 and py.istr(s[0]): key_defs = U.get(u_key_defs) if not key_defs: key_defs = [] for k, v in pyppeteer.us_keyboard_layout.keyDefinitions.items(): if py.len(k) > 1: key_defs.append(k) U.set(u_key_defs, key_defs) ## cache end if s not in key_defs: # if in, s=tuple(skey) s = s[0] xy = Win.click(*xy) for k in s: await page.keyboard.press(k) return s, xy
def forwardReq(a): # url_path = urlparse(a.path).path # if not url_path == '/0':return a.send_not_found() # method U.msgbox(a.command) req = urlparse.urlparse(a.path).query reqs = urlparse.parse_qs(req, keep_blank_values=True) if len(reqs) == 0: a.send_response('text/html', U.read(U.getModPath() + 'file/webControl.html')) # U.msgbox([i for i in sys.modules if 'webC' in i]) U.r(sys.modules['qgb.N.webControl']) return from qgb import Win as w if len(reqs) == 1: # t=T.subLast(a.path,'t=','') or 0 # t=int(t) t = int(reqs['t'][0]) if t & WUP: for i in range(5): w.mouse_event(0, 0, t, move=False, abs=True) if t & WDOWN: for i in range(3): w.mouse_event(0, 0, t, move=False, abs=True) w.mouse_event(0, 0, t, move=False, abs=True) # a.send_response('text/html',w.getLastErr()) # a.wfile.write('\r\n'*5) return if len(reqs) == 2: x = int(reqs['x'][0]) y = int(reqs['y'][0]) w.setCurPos(x, y) return
def istop(): x, y = Win.getCurPos() if y > giClickY * 6 or y > ih - 9: U.pln(iw, ih, i, 'Cur:', x, y) U.exit()
#coding=utf-8 import S gsTitle = '- Yandex Browser' giClickY = 34 from qgb import py, Win, U, T, N, F # U=py.importU() from pywinauto import Application app = Application() pids = [i[0] for i in Win.getAllWindows() if i[1].endswith(gsTitle)] ws = [] for i in pids: i = app.Connect(handle=i) i = i.windows() for w in i: if w.WindowText().endswith(gsTitle): if w not in ws: ws.append(w) # F.dill_dump(obj=ws,file='browserGo_ws') U.pprint(U.il(ws)) if U.ct(ws) == 0: Win.setCurPos(giClickY, giClickY) def istop(): x, y = Win.getCurPos() if y > giClickY * 6 or y > ih - 9: U.pln(iw, ih, i, 'Cur:', x, y) U.exit() def click(w, x, y=giClickY): istop() try:
def _registed_click_pop_cart(): if U.isWin(): from qgb import Win ox, oy = Win.get_cursor_pos() x, y = 1080, 123 Win.click(884, 717) #scroll bottom U.sleep(0.3) Win.click(657, 674) #add btn U.sleep(1.6) for i in range(19): if Win.get_color([889, 485]) != 12698049: #grey Win.click(1080, 123) #pop btn U.log(i) break U.sleep(0.3) else: return 'error' Win.click(888, 274) #s top U.sleep(0.3) Win.click(ox, oy) return ox, oy
def mouse_event(x, y, event=0, abs=True, move=True): ''' x,y int :depand abs (Don't input base 65535) x,y float 0-1.0: rel screen x abs False:从上一次鼠标位置移动 Win.mouse_event(0,0) 没有反应? Return value This function has no return value. Remarks dwData>0 scroll up <0 down If the mouse has moved, indicated by MOUSEEVENTF_MOVE being set, dx and dy hold information about that motion. The information is specified as absolute or relative integer values. If MOUSEEVENTF_ABSOLUTE value is specified, dx and dy contain normalized absolute coordinates between 0 and 65,535. The event procedure maps these coordinates onto the display surface. Coordinate (0,0) maps onto the upper-left corner of the display surface, (65535,65535) maps onto the lower-right corner. If the MOUSEEVENTF_ABSOLUTE value is not specified, dx and dy specify relative motions from when the last mouse event was generated (the last reported position). Positive values mean the mouse moved right (or down); negative values mean the mouse moved left (or up). ======================================= MOUSEEVENTF_ABSOLUTE 0x8000 The dx and dy parameters contain normalized absolute coordinates. If not set, those parameters contain relative data: the change in position since the last reported position. This flag can be set, or not set, regardless of what kind of mouse or mouse-like device, if any, is connected to the system. For further information about relative mouse motion, see the following Remarks section. MOUSEEVENTF_LEFTDOWN 0x0002 The left button is down. x,y useless? |MOUSE_MOVE Win.mouse_event(90,90,2|1,False)#x,y 无用 Win.mouse_event(90,90,2|1,True)#有用,并立即返回 Win.mouse_event(65536,65536,0) -------> Win.getCursorPos() Out[76]: (1365L, 767L) ''' W, H = getScreenSize() if type(x) is float: if abs: x = int(65535 * x) y = int(65535 * y) else: x = int(W * x) y = int(H * y) else: if abs: x = float(x) / W y = float(y) / H x = int(65535 * x) y = int(65535 * y) dwData = 0 if abs: event = event | mouse_event.ABSOLUTE if move: event = event | mouse_event.MOVE #2|1|1|1== 3 # if WHEEL&event: if mouse_event.WDOWN & event: dwData = -9 event |= mouse_event.WHEEL if mouse_event.WUP & event: dwData = 9 event |= mouse_event.WHEEL User32.mouse_event.argtypes = [ DWORD, DWORD, DWORD, DWORD, ctypes.wintypes.c_void_p ] #ULONG_PTR U = py.importU() if U.debug(): U.pln(event, x, y, dwData, None) User32.mouse_event(event, x, y, dwData, None)
def SetForegroundWindow(title=None, handle=None, pid=None, process_name='', raise_error=0, retry=99, **ka): U, T, N, F = py.importUTNF() if py.isint(title) and not handle: handle, title = title, '' if not title: title = U.get_duplicated_kargs( ka, 't', ) if not handle: handle = U.get_duplicated_kargs(ka, 'hwnd', 'h') if not process_name: process_name = U.get_duplicated_kargs(ka, 'name', 'pn', 'process') no_raise = U.get_duplicated_kargs(ka, 'no_raise', 'noRaise', 'no_raise_err', default=not raise_error) raise_error = (not no_raise) or U.get_duplicated_kargs( ka, 'err', 'error', 'exp', 'exception', 'Exception', 'raise_err', 'raise_error', 'raiseError', 'raiseErr', 'raise_EnvironmentError', 'EnvironmentError', 'raiseEnvironmentError', default=raise_error) if not handle and not title and not pid and not process_name: handle = get_current_cmd_windows() if not handle: from qgb import Win for h, t, p in Win.getAllWindows(): if t == title or p == pid: handle = h break if process_name and process_name == U.get_process_name_by_pid(p): handle = h break else: if (not title) and (not process_name): raise py.ArgumentError(py.locals()) for h, t, p in Win.getAllWindows(): if title and title in t: handle = h break if process_name and process_name in U.get_process_name_by_pid( p): handle = h break else: if raise_error: raise py.EnvironmentError( 'cannot find ForegroundWindow title : ' + a) # if py.isint(title): # handle=title # else: # raise py.ArgumentError('foreground,a',row) import win32gui # if not win32gui.IsWindowVisible(handle): #先不考虑 try: # win32gui.SetForegroundWindow(handle) import win32gui, win32com.client, win32con, pythoncom pythoncom.CoInitialize( ) #加上这句解决 #pywintypes.com_error: (-2147221008, '尚未调用 CoInitialize。', None, None) shell = win32com.client.Dispatch("WScript.Shell") shell.SendKeys('%') ##For ALT prefix with % win32gui.ShowWindow(handle, win32con.SW_SHOW) win32gui.SetForegroundWindow(handle) except Exception as e: #BUG 窗口在后台,通过 http_rpc 调用此函数,第一次总会出错:,第二次才成功? # error(0, 'SetForegroundWindow', 'No error message is available') if 'No error message is available' in repr(e): for i in py.range(1, retry): try: if i % 9 == 1: U.sleep(0.01) # sleep一下有奇效,为什么? win32gui.SetForegroundWindow(handle) return U.IntCustomRepr( handle, repr='Win.set_foreground(%r) #retry:%s' % (handle, i)) except: pass # return py.No(e,'') if raise_error: raise return py.No(e) return U.IntCustomRepr(handle, repr='Win.set_foreground(%r)' % handle)