vbapowershellsendkeyscitrix

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


I have powershell script that automate some tasks I am doing. We are using Citrix and in order to get to an app in Citrix I am using Selenium. The main problem in Citrix is that I can only use SendKeys to automate within the app after Selenium clicked it because I actually see a "Remote" UI.

My Code:

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

I am loading System.Windows.Forms with Add-Type, and using [System.Windows.Forms.SendKeys]::SendWait() to SendKeys.

I am using "Space" (" ") to focus and "{Enter}" to enter Settings UI, that's working.. But within the new settings UI window I can't seems to press "ALT" using the SendKeys to navigate to the menu and open it.

What weird about this problem is:

  1. The window that opened the settings UI react properly to the SendKeys.
  2. When I am not using SendKeys within the settings UI, but rather I click the ALT on the keyboard, the settings UI reacts properly to me smashing my keyboard...
  3. The ALT sendkey works, because the ALT reacts fine when on Notepad or other application.

Thanks!

I tried to use VBA AppActivate, no success.


Solution

  • There is a problem using [System.Windows.Forms.SendKeys] class with Citrix, because Citrix terminal server can't handle special tabs using the SendKeys. The solution is to download AutoIT and take out the .dll files (3 files). Then load it to your C# code or to the Powershell and use it. AutoIT sendkeys seems to interact just fine with citrix terminal servers and your automation can work fine with the sendkeys.