TShopping

標題: python 如何抓取視窗位址及在視窗輸入文字 [打印本頁]

作者: woff    時間: 2024-1-15 23:47
標題: python 如何抓取視窗位址及在視窗輸入文字
  1. import ctypes
  2. import time
  3. import keyboard
  4. import win32gui

  5. def click_left(x,y,click_s):
  6.     ctypes.windll.user32.SetCursorPos(x, y)
  7.     ctypes.windll.user32.mouse_event(2,0,0,0,0)
  8.     #滑鼠點擊間隔時間
  9.     #print(x,y)
  10.     time.sleep(click_s)
  11.     ctypes.windll.user32.mouse_event(4,0,0,0,0)

  12. def callback(hwnd, extra):
  13.     rect = win32gui.GetWindowRect(hwnd)
  14.     x = rect[0]  # 視窗起始位置x
  15.     y = rect[1]  # 視窗起始位置y
  16.     w = rect[2] - x # 視窗大小x
  17.     h = rect[3] - y # 視窗大小y
  18.     if "xxxx" in win32gui.GetWindowText(hwnd):
  19.         # print("Window %s:" % win32gui.GetWindowText(hwnd))
  20.         # print("\tLocation: (%d, %d)" % (x, y))
  21.         # print("\t    Size: (%d, %d)" % (w, h))
  22.         click_left(x + 1, y + 1, 1)


  23. win32gui.EnumWindows(callback, None)

  24. time.sleep(2)
  25. keyboard.press_and_release('y')  #輸入y
  26. keyboard.press_and_release('e')  #輸入e
  27. keyboard.press_and_release('s')  #輸入s
  28. keyboard.press_and_release('enter') #壓enter
複製代碼




新竹網頁設計,竹北網頁設計,竹南網頁設計,中壢網頁設計,網頁設計,免費模板,免費網頁套件,架設網站,網站架設 ,修改模板,主機代管,Android App




歡迎光臨 TShopping (http://www.tshopping.com.tw/) Powered by Discuz! X3.2