在WPF应用程序SendKeys.Send方法应用程序、方法、WPF、Send

2023-09-03 00:30:05 作者:你与清晨阳光

我要发送按键(按Ctrl + T)的浏览器控件。但是, SendKeys.Send()显示在WPF应用程序错误?我的问题是

I'm trying to send Keystroke(Ctrl+T) for browser control. But, SendKeys.Send() showed error in WPF application?? My question is

1)在WPF应用程序可以我用这个方法?

1) Can I use this method in WPF application?

2)是否有其他方法来回回发送自动按键。

2) Is there any alternative method fro sending automatic keystroke.

感谢。

推荐答案

的SendKeys是System.Windows.Forms命名空间的一部分,没有在WPF等效方法。你不能使用SendKeys.Send使用WPF,但你可以使用SendKeys.SendWait方法,如果您添加System.Windows.Forms的到你的项目引用。你唯一的选择是向PInvoke的 SendInput 。

SendKeys is part of the System.Windows.Forms Namespace there is not an equivalent method in Wpf. You can not use the SendKeys.Send with WPF but you can use the SendKeys.SendWait method, if you add System.Windows.Forms to your project references. Your only other option would be to to PInvoke SendInput.

请注意,这两种方法将数据发送到当前活动窗口。

Be aware that both of these methods send data to the currently active window.