TShopping

 找回密碼
 註冊
搜索
查看: 225|回復: 0
打印 上一主題 下一主題

[教學] python 如何抓取視窗位址及在視窗輸入文字

[複製鏈接]
跳轉到指定樓層
1#
發表於 2024-1-15 23:47:03 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
 
Push to Facebook
  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

 

臉書網友討論
*滑块验证:
您需要登錄後才可以回帖 登錄 | 註冊 |

本版積分規則



Archiver|手機版|小黑屋|免責聲明|TShopping

GMT+8, 2024-4-28 01:03 , Processed in 0.056975 second(s), 22 queries .

本論壇言論純屬發表者個人意見,與 TShopping綜合論壇 立場無關 如有意見侵犯了您的權益 請寫信聯絡我們。

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表