简体   繁体   中英

How to send keystrokes/messages to Windows 7 with C++ and Windows API?

Is it possible for a program to send keystrokes or messages to Windows 7 (the operating system it's running on) to simulate the effect of a user physically pressing the Windows key on their keyboard, for example; in C++, using the Windows API?

SendInput函数已经使用了很长时间了,应该可以满足您的需要。

Beginners often try to send keys to windows because they think it is the easiest solution. It is sure easy to reply by saying it is possible. Often, after the developer invests a significant amount of time, it becomes complicated. One reason it is complicated is because you must ensure that the control (the textbox or whatever) has the focus. Then you have to do something to get the data processed, such as push a button. You might need to read the window to decide what to do next.

An alternative is to go up a level and try to control anapplication by accessing the controls and their parent (the window). So in other words you can put data into a textbox directly as a string, not by typing keys into it. You can send a BN_CLICKED notification message to the wndow instead of sending an enter key to the button to click the button. You should look for ways to do that type of thing. It is totally possible.

Become familiar with Spy++; it is a tool that can really help you to explore the controls and windows and such.

您可以使用SendInput进行任何模拟的输入,但是,您会受到应用程序完整性级别的约束(也就是说,您无法将输入注入到具有更高级别的应用程序中)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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