2

コンテキスト:ユーザーがテキストを入力できるように、タッチスクリーンキオスクのオンスクリーンキーボードを使用しています。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");
}

ActiveSourceがnullのKeyEventArgsを使用できず、System.Windows.Forms.SendKeys.SendWait( "{BACKSPACE}")も機能しません。

4

1 に答える 1

6

ソースを偽装して、次のように修正しました。

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);
}
于 2010-09-03T23:41:34.980 に答える