简体   繁体   English

使用keybd_event

[英]Using keybd_event

I have a simple program that does some 'typing' with keybd_event() . 我有一个简单的程序,对keybd_event()一些“输入”。 The problem is that when I focus the program window, any text box where I want to type (eg in a browser) becomes unfocused. 问题是当我聚焦程序窗口时,我要键入的任何文本框(例如在浏览器中)都变得不聚焦。 How do I remedy that? 我该如何补救?

Pass the hwnd of the textbox you want to type in instead of the window who owns it, this should solve your problems. 传递您要键入的文本框的hwnd而不是拥有它的窗口,这应该可以解决您的问题。 You might need to enumerate the child windows though, to get the correct resource ids of the textboxes. 但是,您可能需要枚举子窗口,以获取文本框的正确资源ID。 You should how be using SendInput , as you might find you method just not working in certain situations, see all the comments. 您应该如何使用SendInput ,因为您可能会发现您的方法在某些情况下不起作用,请参阅所有注释。

如果要防止正在生成键盘事件的应用程序获得焦点,一种选择是使用WS_EX_NOACTIVATE扩展样式创建应用程序窗口

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM