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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Win32Api - want to stuff keyboard in another application

Status
Not open for further replies.

OnQueIT

Programmer
Nov 12, 2003
18
US
2 part question: (1)Is there a list of functions available from win32api. (2) I figured out how to popup(bring to the front) another application by using the BringWindowToTop(win32api) and ShowWindow(win32api).

Actual question: I want to send data to that application after it becomes the current application. Is there a function in win32api or a way to do a keyboard stuff from VFP into another application that is running?
 
2-part answer:

1. List of API functions.

The best one I know is As well as the API details, it has VFP DECLAREs and examples.

2. Sending keystrokes to other applications.

Code:
oWSH = CREATEOBJECT("wscript.shell")
oWSH.AppActivate("Some Application")
oWSH.SendKeys("Hello World")

This assumes that "Some Application" is the title of the application's window. If it's a particularly large app, you might need to wait a few millisecs after activating it and before sending the keys.

To send modified keys, use these codes:
+ shift
^ ctrl
% alt

For example, %FO will do Alt+F, O which is usually File / Open.

Hope this helps.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
The SendKeys function did insert the string but did not insert the keystrokes at the current cursor location. From the initial application screen there is an input box selected from the menu and is the current form in the application. The SendKeys function sends the data to the first/current textbox of the initial form instead of the current form. So, the data goes to the wrong place. Interestly enough, when I do the ShowWindow function it shows the initial form, as soon as I issue a _SCREEN.windowstate=1(to min VFP), the screen state of the application goes from the initial form to the input box.

Do you know of any other way to send keystrokes(or a text string) into the current application at the current cursor position?
 
You don't need another way to do it. Sendkeys() will do what you want. You just need to move the cursor to the correct control. You can do that by sending the apppropriate number of tab characters before you send the actual text.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
I think this will work for me. How do I send a Function key(F5 or F2)?
 
After I sent the last post, I realized I also need to know other keys. Left and Right arrow and ENTER. Are these {LEFTARROW}, {RIGHTARROW}, {ENTER}. Is TAB, {TAB}?
 
Yes, more or less. Except that Left is {LEFT}, not {LEFTARROW}.

I'm happy to help you as much as I can. But, you know, these are all simple points that you can easily find out about by looking at the SendKeys() function on the Microsoft site.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Mike, thanks a bunch for following up. The Microsoft site filled in a few more blanks. I've been busy coding and testing and last night got very thing working 100% correct. There is no way I could have completed this task without your help so for that I say thank you. In the future I promise to pay it forward.

By the way, I guy in NY suggested I use a product called WinBatch( which allows the user to create scripts(WIL files) which does nothing more than use wscript from within a VB program to execute the code the user creates. I wanted to stay true to VFP and not user a third party(VB) program to accomplish this task and thanks to you I did it.
 
OnQueIT,

You're very welcome. I'm delighted you've got it working. (And my apologies for any hint of sarcasm in my tone.)

I vaguely remember trying WinBatch quite a few years ago - back in Windows 97 days, I think. It was a good product, but, like you, I prefer to stay within the VFP world where possible.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top