How do I simulate a Tab key press when Return is pressed in a WPF application?

后端 未结 7 2042
悲哀的现实
悲哀的现实 2021-01-01 16:37

In a WPF application, i have a window that has a lot of fields. When the user uses the TAB key after filling each field, windows understands that it moves on to the next. Th

相关标签:
7条回答
  • 2021-01-01 17:03

    SendKeys.Send or SendKeys.SendWait will not work in a WPF application, so to answer the original question

    if (e.Key == Key.Return)
    {    
        KeyEventArgs tabPressEventArgs = new KeyEventArgs(Keyboard.PrimaryDevice, Keyboard.PrimaryDevice.ActiveSource, 0, Key.Tab) { RoutedEvent = Keyboard.KeyDownEvent };
        InputManager.Current.ProcessInput(tabPressEventArgs); 
    }
    
    0 讨论(0)
提交回复
热议问题