I would like to be able to programmatically emulate the keyboard navigation for dialog boxes.
我希望能够以编程方式模拟对话框的键盘导航。
I have a custom hardware device with a keypad that I would like to use for dialog box navigation.
我有一个带键盘的自定义硬件设备,我想用它来进行对话框导航。
I know about Focus(), but I'd rather do something that automatically respected the tab order. By emulating the keyboard navigation I don't have to worry about re-inventing complex behavior for each type of control.
我知道Focus(),但我宁愿做一些自动遵守Tab键顺序的东西。通过模拟键盘导航,我不必担心为每种类型的控件重新发明复杂的行为。
Does anyone know how to do this?
有谁知道如何做到这一点?
Thanks!
3 个解决方案
#1
You could use P/Invoke to call the Windows API function keybd_event to simulate pressing the Tab key.
您可以使用P / Invoke调用Windows API函数keybd_event来模拟按Tab键。
Bonus: you can use your device to enter tabs into a text editor as well! ;)
额外奖励:您也可以使用您的设备在文本编辑器中输入标签! ;)
#2
For Winforms, you want want the Control.GetNextControl()
method
对于Winforms,您需要Control.GetNextControl()方法
For WPF, you want the UIElement.MoveFocus()
method
对于WPF,您需要UIElement.MoveFocus()方法
#3
In Winforms:
Control nextControl = this.GetNextControl(myControl, true);
To simulate a tab press, I believe it's the following:
要模拟标签按,我相信它是以下内容:
SendKeys.Send("{TAB}");
#1
You could use P/Invoke to call the Windows API function keybd_event to simulate pressing the Tab key.
您可以使用P / Invoke调用Windows API函数keybd_event来模拟按Tab键。
Bonus: you can use your device to enter tabs into a text editor as well! ;)
额外奖励:您也可以使用您的设备在文本编辑器中输入标签! ;)
#2
For Winforms, you want want the Control.GetNextControl()
method
对于Winforms,您需要Control.GetNextControl()方法
For WPF, you want the UIElement.MoveFocus()
method
对于WPF,您需要UIElement.MoveFocus()方法
#3
In Winforms:
Control nextControl = this.GetNextControl(myControl, true);
To simulate a tab press, I believe it's the following:
要模拟标签按,我相信它是以下内容:
SendKeys.Send("{TAB}");