如何仅将击键发送到一个程序?

发布于 2024-08-22 08:34:48 字数 363 浏览 3 评论 0原文

我一直很难找到任何有用的东西,但我发现有人问如何做到这一点,(如何将击键发送到窗口?

如果使用代码,我可以设置记事本的文本,但我想发送按键但设置文本,我 想要发送像 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鸵鸟症 2024-08-29 08:34:48

听起来您正试图在发送密钥之前使窗口获得焦点。查看 FindWindowSetForegroundWindow

像这样的东西应该有效:

SetForegroundWindow(FindWindow(0,"Untitled - Notepad"));
keybd_event(....);

如果您正在谈论直接更改窗口的文本,请查看 GetWindow 导航窗口树和 SendMessage 带有 WM_SETTEXT 参数。

Sounds like you're trying to make a window have the focus before sending your keys. Look at FindWindow and SetForegroundWindow.

Something like this should work:

SetForegroundWindow(FindWindow(0,"Untitled - Notepad"));
keybd_event(....);

If instead you're talking about changing a window's text directly, look at GetWindow to navigate the window tree and SendMessage with a WM_SETTEXT parameter.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文