簡體   English   中英

Powershell [System.Windows.Forms.SendKey],ALT 無法正常工作

[英]Powershell [System.Windows.Forms.SendKey], ALT don't work properly

我有 powershell 腳本可以自動執行我正在執行的一些任務。 我們正在使用 Citrix,為了訪問 Citrix 中的應用程序,我使用的是 Selenium。Citrix 中的主要問題是,在 Selenium 單擊它后,我只能使用 SendKeys 在應用程序中實現自動化,因為我實際上看到了一個“遠程”用戶界面。

我的代碼:

Add-Type -AssemblyName System.Windows.Forms

Start-Sleep -Seconds 5
[System.Windows.Forms.SendKeys]::SendWait(" ") ## Space to focus on item
Start-Sleep -Seconds 1
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}") ## Enter to get into Printer Settings UI
Start-Sleep -Seconds 2
[System.Windows.Forms.SendKeys]::SendWait("%") ## ALT to focus on the menu
Start-Sleep -Seconds 1
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}") ## Enter to open the menu

我正在使用 Add-Type 加載 System.Windows.Forms,並使用 [System.Windows.Forms.SendKeys]::SendWait() 到 SendKeys。

我正在使用“Space”(“”)聚焦並使用“{Enter}”進入設置用戶界面,這是有效的..但在新設置用戶界面 window 中,我似乎無法使用 SendKeys 按“ALT”導航到菜單並打開它。

這個問題的奇怪之處在於:

  1. 打開設置 UI 的 window 對 SendKeys 做出正確反應。
  2. 當我沒有在設置 UI 中使用 SendKeys,而是單擊鍵盤上的 ALT 鍵時,設置 UI 會正確地對我敲擊鍵盤做出反應...
  3. ALT sendkey 有效,因為 ALT 在記事本或其他應用程序上反應良好。

謝謝!

我嘗試使用 VBA AppActivate,但沒有成功。

在 Citrix 中使用 [System.Windows.Forms.SendKeys] class 時出現問題,因為 Citrix 終端服務器無法使用 SendKeys 處理特殊選項卡。 解決方法是下載AutoIT,取出.dll個文件(3個文件)。 然后將其加載到您的 C# 代碼或 Powershell 並使用它。 AutoIT sendkeys 似乎可以與 citrix 終端服務器很好地交互,並且您的自動化可以很好地與 sendkeys 一起工作。

暫無
暫無

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

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