woff 發表於 2024-1-15 23:47:03

python 如何抓取視窗位址及在視窗輸入文字

import ctypes
import time
import keyboard
import win32gui

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

def callback(hwnd, extra):
    rect = win32gui.GetWindowRect(hwnd)
    x = rect# 視窗起始位置x
    y = rect# 視窗起始位置y
    w = rect - x # 視窗大小x
    h = rect - y # 視窗大小y
    if "xxxx" in win32gui.GetWindowText(hwnd):
      # print("Window %s:" % win32gui.GetWindowText(hwnd))
      # print("\tLocation: (%d, %d)" % (x, y))
      # print("\t    Size: (%d, %d)" % (w, h))
      click_left(x + 1, y + 1, 1)


win32gui.EnumWindows(callback, None)

time.sleep(2)
keyboard.press_and_release('y')#輸入y
keyboard.press_and_release('e')#輸入e
keyboard.press_and_release('s')#輸入s
keyboard.press_and_release('enter') #壓enter



新竹網頁設計,竹北網頁設計,竹南網頁設計,中壢網頁設計,網頁設計,免費模板,免費網頁套件,架設網站,網站架設 ,修改模板,主機代管,Android App
頁: [1]
查看完整版本: python 如何抓取視窗位址及在視窗輸入文字