在Python 中取得活動視窗
擷取螢幕上的活動視窗對於自動執行任務(例如輸入使用者名稱和密碼)至關重要。對於 Python 用戶,有幾個函式庫提供了實現此目的的功能。
使用 Python 進行 Windows 擴充
pywin32 函式庫是 Python 的一個擴展,可以使用 Windows API功能。使用 pywin32 取得活動視窗:
from win32gui import GetWindowText, GetForegroundWindow
# Get the handle of the foreground window
hwnd = GetForegroundWindow()
# Get the window title
window_title = GetWindowText(hwnd)
# Print the window title
print(window_title)
注意:在Python 3中,應該使用print(window_title)而不是print window_title。
替代庫
其他庫可以用於此目的include:
免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。
Copyright© 2022 湘ICP备2022001581号-3