WPF:如何与非活动窗口交互?
是否可以从另一个窗口与非活动窗口进行交互?我想将窗口中的文本框聚焦而不使其处于活动状态,然后向其发送击键和鼠标事件。似乎可以使用 SendMessage 将消息发送到非活动窗口,但是是否也可以将窗口中的文本框聚焦并向其发送击键,而无需使窗口处于活动状态?
Is it possible to interact with an inactive window from another window? I want to focus a textbox in a window without making it active, and then send keystrokes and mouse events to it. It seem to be possible to send messages to inactive windows using SendMessage but could it be possible to also focus a textbox in the window and send keystrokes to it, without ever making the window active?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看看措辞稍有不同的同一问题 此处
引用 @Kevin Montrose:“Windows 假定激活窗口是获取键盘输入的窗口,伪造键盘输入的正确方法是使用 SendInput,您将请注意,它仅向活动窗口发送消息。”
Have a look at the same question worded a little different here
Quote @Kevin Montrose: "Windows assumes that the activate window is the one getting keyboard input. The proper way to fake keyboard input is with SendInput, and you'll notice that it sends messages to the active window only."
您是否看过UI 自动化?
获取模式并调用并不难。我唯一不确定的是窗口是否会获得焦点。
当然这只能在同一个进程中起作用。
Did you have a look at UI Automation?
Getting a pattern and invoking it isn't that hard. The only thing I am not sure about is whether or not the window will get the focus.
Of course this will only work in the same process.