ss7thirty
Well-known member
I am working on a program and wish to add some extra functionality to the application. I wish to recognize other windows that are gaining focus. And based on which windows takes focus it will send keystrokes to that window. Sometimes closing it, sometimes sending information, sometimes doing nothing. I wish to know which API call or appropriate .NET function there is to gain control of the active window (often outside of the application).
For example, if my application is running and someone clicks on notepad, my application will recognize that a new windows has gained focus and that this is not a window that I need. If they open one of the windows I am looking for I would like to be able to send keystrokes to this application (Which I know how to do) and possibly get text from a textbox (Don't know). This application could be written in a variety of different languages and therefore I need to use functions that are not platform dependant to retrieve information from another application/window.
I have been researching this for a while but am still drawing blanks. But there has to be a way to see what window has gained focus and retrieve text from the various controls on that windows. After all, Windows does it. You can highlight the text and copy it and windows will then store it into memory so then what do I have to do to essentially force the same action programmatically when a certain windows comes into focus.
I have done some additional research and found a Visual C++ Project that did some similar things. It is open source, however, I am having trouble interpreting some of the code because it is pretty complex. However, it does prove that this is possible, I am just not sure if it can be easily accomplished in VB.NET. The following link contains the source code and the executable. The executable is all that needs to be reviewed if I can just figure out which API calls they are making or how they access the information that they access I should be able to easily figure out how to implement it. Anyway, here is the link:
http://www.nirsoft.net/utils/winexp.html
For example, if my application is running and someone clicks on notepad, my application will recognize that a new windows has gained focus and that this is not a window that I need. If they open one of the windows I am looking for I would like to be able to send keystrokes to this application (Which I know how to do) and possibly get text from a textbox (Don't know). This application could be written in a variety of different languages and therefore I need to use functions that are not platform dependant to retrieve information from another application/window.
I have been researching this for a while but am still drawing blanks. But there has to be a way to see what window has gained focus and retrieve text from the various controls on that windows. After all, Windows does it. You can highlight the text and copy it and windows will then store it into memory so then what do I have to do to essentially force the same action programmatically when a certain windows comes into focus.
I have done some additional research and found a Visual C++ Project that did some similar things. It is open source, however, I am having trouble interpreting some of the code because it is pretty complex. However, it does prove that this is possible, I am just not sure if it can be easily accomplished in VB.NET. The following link contains the source code and the executable. The executable is all that needs to be reviewed if I can just figure out which API calls they are making or how they access the information that they access I should be able to easily figure out how to implement it. Anyway, here is the link:
http://www.nirsoft.net/utils/winexp.html
Last edited: