簡體   English   中英

如何在屏幕上找到文本並使用 c# 獲取其坐標?

[英]How can I find text on screen and get its coordinates using c#?

我想自動化安裝在我機器上的軟件。 我正在使用 AutoIt,但在一個屏幕上我無法獲得控件 ID 或標題,因此我可以訪問該控件,然后在其中查找文本。 我想點擊那個文本,所以我需要那個文本的坐標。 我如何使用 c# 代碼或任何其他第三方工具來協調該文本? 我已經在谷歌上查過,但我找不到任何有趣或有用的東西。 任何與此問題相關的事情將不勝感激。

正如其他人所說,你問的問題有點模糊。 您希望使用哪種軟件實現自動化? 你想更精確地自動化什么? (鼠標操作?點擊?軟件上有什么特別的東西?..)

例如,關於鼠標點擊,有兩種主要的方法來自動化一個過程:基於屏幕坐標的點擊或基於窗口坐標的點擊。 在下面,您可以找到一個示例來自動安裝來自“Web 平台安裝程序 5.0” (您可以從 Microsoft 網站 @ https://azure.microsoft.com/en-us/tools/下載)中的特定應用程序—— >視覺工作室2015)

;Gives Admin rights to autoIT
#RequireAdmin
;launches the program in the same directory as the installer
Run(@ScriptDir & '\azure.exe')
;Sets the coordinates as window coordinates with "0" (VS screen coordinates) 
AutoItSetOption('MouseCoordMode',0)
;Waits for the program to open and to display a text like "Microsoft Web Platform Installer"
WinWait("Web Platform Installer 5.0","Microsoft Web Platform Installer")

;wait 1.5 seconds
sleep(1500)
;When the window is visible, le cursor is set as active ont that window (IMPORTANT)

WinActivate("Web Platform Installer 5.0")
;the following commands are mouseclicks on specific boxes of the program to automate specific installs on the installer
;MouseClick('primary', x, y, 1, speed (1 to 10))
; You will find those coordinates in the "AU3info.exe file" after you've installed autoIT ( Au3info allows to find coordinates
; by targeting specific places on a window)
MouseClick('primary', 155, 60, 1, 10)
sleep(1500)
;selects 4 apps to be installed (4 installs), clics INSTALL and waits 1.5 sec
MouseClick('primary', 817, 122, 1, 10)
MouseClick('primary', 821, 163, 1, 10)
MouseClick('primary', 815, 401, 1, 10)
MouseClick('primary', 828, 519, 1, 10)
MouseClick('primary', 692, 587, 1, 10)
sleep(1500)
;Prepaing the install and waiting till a text like "Review the following list" apprears
WinWait("Web Platform Installer 5.0","Review the following list")
WinActivate("Web Platform Installer 5.0")
sleep(1500)
MouseClick('primary', 43, 350, 1, 10)
MouseClick('primary', 603, 433, 1, 10)
;starts the installation and waits till the installation is finished (when "The following"..programm has installed ..blabla
WinWait("Web Platform Installer 5.0","The following")
MouseClick('primary', 612, 434, 1, 2)
;gets rid of some issues stemming from microsoft edge (the send functions allows to send keyboard keys (like ESC, SPACE, ALT, etc..))
sleep(1000)
Send("{ENTER}")
MouseClick('primary', 612, 434, 1, 2)
sleep(1000)
Send("{ENTER}")
;quits all the windows with ALT + F4
WinWait("Web Platform Installer 5.0")
WinActivate("Web Platform Installer 5.0")
Sleep(1000)
Send("{ALT down}{F4 down}{F4 up}{ALT up}")
Sleep(1000)
Send("{ALT down}{F4 down}{F4 up}{ALT up}")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM