gpt4 book ai didi

c# - 使用空 ActiveSource 在 C# 中模拟按 Backspace 按钮

转载 作者:行者123 更新时间:2023-12-01 19:45:20 25 4
gpt4 key购买 nike

上下文:我们在触摸屏信息亭上使用屏幕键盘来允许用户输入文本。退格按钮失败,因为 System.Windows.Input.Keyboard.PrimaryDevice.ActiveSource 变为 null。

代码上下文:

if (System.Windows.Input.Keyboard.PrimaryDevice.ActiveSource != null)
{
System.Windows.Input.KeyEventArgs ke =
new System.Windows.Input.KeyEventArgs(
System.Windows.Input.Keyboard.PrimaryDevice,
System.Windows.Input.Keyboard.PrimaryDevice.ActiveSource,
0,
System.Windows.Input.Key.Back);
ke.RoutedEvent = UIElement.KeyDownEvent;
System.Windows.Input.InputManager.Current.ProcessInput(ke);
}
else
{
Console.Out.WriteLine("Problemo");
}

我无法将 KeyEventArgs 与 null ActiveSource 一起使用,并且 System.Windows.Forms.SendKeys.SendWait("{BACKSPACE}") 也不起作用。

最佳答案

我只是欺骗了源代码来修复它,如下所示:

else
{
//Hacky? Perhaps... but it works.
PresentationSource source = PresentationSource.FromVisual(this);
KeyEventArgs ke = new KeyEventArgs(
Keyboard.PrimaryDevice,
source,
0,
System.Windows.Input.Key.Back);
ke.RoutedEvent = UIElement.KeyDownEvent;
System.Windows.Input.InputManager.Current.ProcessInput(ke);
}

关于c# - 使用空 ActiveSource 在 C# 中模拟按 Backspace 按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3640128/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com