Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending commands to another program (like Sendkeys) 2

Status
Not open for further replies.

ErroR

Technical User
Apr 9, 2001
79
US
Ok, what I want to be able to do is send commands to third party program, just as if they were keystrokes/mouse commands... but I don't want it to be like the standard SendKeys where it is interactive and requires the target program to have focus.

What I'm trying to do is interface with peices of software, just like a user. However, I want the workstation to be available in other was, while this process runs. So basically, a non-interactive SendKeys function.

Anyone?
 
you can use WINSOCK. See the MSDN disk help example of talking between two separate apps on the one computer.

I think I saw an API that can do this using the handle of the app but I cant remember where I saw it. Browse thru the API forum.
 
sunaj, those are a great step in the right direction... thanks very much. I'm having trouble now trying to find how the hell to set the input focus to another application.

The function SetFocus() I find out will not set the focus to the handle of another program other than the thread calling the function. No dice...

What I want is for my VB application to run, without focus, and send keystrokes and mouse events to yet another application which may or may not be the active window on the desktop. Does that makes sense?

Say my VBApp is called Robot, it controls an application called Calculator and the user is currently has another application with the focus, say he's watching a DOS display scroll by. Robot should send the keystrokes and mouse events to Calculator, even though Calculator nor Robot are active with focus.
 
Coincidentally, I've just answered a question on this very subject in the Win32 forum, with example code. The trick is to use the AttachInputThread API call. Oh, and the example is a lowest common denominator version in that it uses mouse_event and keybd_event so it should work with all vesrions of Windows from 95 onwards. SendInput would also work, and would be the preferred option going forward. Here's the thread you might want to look at: thread713-317089
 
That's kinda funny, I had went over and marked that same thread in the API forum, so I got notified for both of your responses.

My only problem is that this method does not satisfy one of my requirements:

*The receiving thread may or may not have focus at the time the key and mouse events are sent.*

In this code, the apiSetFocus is used, and without it, the receiving thread does not get the text.

Any ideas? Thanks for what provided too.

 

I could be wrong but try getting its process id and hooking into its window. Then you can use sendmessage to click on various objects or type in a textbox etc.
 
vb5prgrmr do you have any examples for hooking into it's window?
 

Not with me but I can give you some hints

API's

GetWindow
GetNextWindow
GetDeskTopWindow
EnumWindows
EnumChildWindows
GetWindowThreadProcessID
GetParent
SendMessage
GetWindowText
IsWindowVisable
IsWindowEnabled
IsWindow

And probably a few more that I cannot remember.

The process would be to enumerate through the available windows looking for the windows text(must be known in advance for this to work) then each control on the program is a window in its-self with properties that you can read. Then once you find the correct window(control) you can then send events to it using sendmessage.

I know that this is not the easiest way to do this but as far as I can tell this will do exactly what you want it to do(even if minimized).

 
Argh!
Everything I look at either requires it to be used in something other than Win9x, OR it will not send the input unless the receiving applications has the active focus.

I know this can be done, I've seen several different game add-on's do it for instance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top