如何仅将击键发送到一个程序?
我一直很难找到任何有用的东西,但我发现有人问如何做到这一点,(如何将击键发送到窗口?)
如果使用代码,我可以设置记事本的文本,但我想发送按键但设置文本,我 想要发送像 keybd_event 这样的密钥,我一直在使用它,但我只想将它发送到一个程序。
keybd_event('a', NULL, NULL, NULL);
keybd_event('a', NULL, KEYEVENTF_KEYUP, NULL);
我怎么能那样做呢?
i have been having a hard time to find anything that is usefull but i found someone asked how to do that,(How to send keystrokes to a window?)
if used the code and i can set notepad's text but i want to send keys but sets the text, i
want to send keys like keybd_event i have been using it but i want to only have it send to one program.
keybd_event('a', NULL, NULL, NULL);
keybd_event('a', NULL, KEYEVENTF_KEYUP, NULL);
how could i do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您正试图在发送密钥之前使窗口获得焦点。查看
FindWindow
和SetForegroundWindow
。像这样的东西应该有效:
如果您正在谈论直接更改窗口的文本,请查看
GetWindow
导航窗口树和SendMessage
带有WM_SETTEXT
参数。Sounds like you're trying to make a window have the focus before sending your keys. Look at
FindWindow
andSetForegroundWindow
.Something like this should work:
If instead you're talking about changing a window's text directly, look at
GetWindow
to navigate the window tree andSendMessage
with aWM_SETTEXT
parameter.