Problem with keyboard in powershell script
TorinKS opened this issue · 1 comments
Hi, I run into problem with keyboard input when use library from powershell script. For example, here is my script:
function Get-ScriptPath
{
Split-Path $myInvocation.ScriptName
}
$moduleName = "$(Get-ScriptPath)\Xaml.dll"
import-module $moduleName
$moduleName = "$(Get-ScriptPath)\ConsoleFramework.dll"
import-module $moduleName
$moduleName = "$(Get-ScriptPath)\Binding.dll"
import-module $moduleName
[ConsoleFramework.Controls.Window] $win =
[ConsoleFramework.Controls.Window][ConsoleFramework.ConsoleApplication]::LoadFromXaml("Layout.xml",$null)
[ConsoleFramework.Controls.WindowsHost] $windowsHost = [ConsoleFramework.Controls.WindowsHost][ConsoleFramework.ConsoleApplication]::LoadFromXaml("windows-host.xml", $null)
$windowsHost.show($win)
# [ConsoleFramework.ConsoleApplication]::Instance.Maximize()
[ConsoleFramework.ConsoleApplication]::Instance.run($windowsHost)
Running application can handle mouse input but not keyboard. What is could be? If you try to run my code you would get "Object reference not set to an instance of an object" exception because Assembly.GetEntryAssembly() returns null when it is called from unmanaged code (powershell)
wow
I even wouldn't think about use cases like this )
LoadFromXaml method tries to load content from embedded resource. If there is no assembly, there is no embedded resources. So, this approach won't work (without patching the library to teach it use external files, for example).
Only that I can advice is to try configure it programmatically, like this:
Window window = new Window();
Panel panel = new Panel();
TextBlock textBlock = new TextBlock();
textBlock.Name = "text";
textBlock.HorizontalAlignment = HorizontalAlignment.Center;
panel.Children.Add(textBlock);
Button button1 = new Button();
button1.Name = "btnMaximize";
button1.Caption = "Maximize";
panel.Children.Add(button1);
Button button2 = new Button();
button2.Name = "btnRestore";
button2.Caption = "Restore";
panel.Children.Add(button2);
window.Content = panel;
window.Created();