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

How to send keys from VFP app to non-VFP app

Status
Not open for further replies.

capri1966

Programmer
May 13, 2010
57
ES
Hi, i would like to know if it is possible to send key secuences from an App developed y VFP 6.0 to another app that is no VFP such as Windows Calculator o NotePad por example.
 
You might look at this thread:

thread184-1658796

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
This is how I would do it:

Code:
oWSH = CREATEOBJECT("wscript.shell")
oWSH.AppActivate("Notepad")   && assumes Notepad is already running
oWSH.SendKeys("Hello world")

You can also send function keys and key combos. For example:

Code:
oWSH.SendKeys("{PGUP}%fSMy File.TXT{ENTER}")
  && %f is ALT+f, so this will execute the File Save As command and 
  && enter a filename

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
In german Windows, this would need to be oWSH.AppActivate("Unbenannt - Editor"), as that would be the caption of the notepad title bar of a new and yet unsaved file.

The approach with an HWND and BringWindowToTop is better suited to get the Window you want, you can get necessary HWND of windows in other ways than just by the FindWindow API function, but it surely becomes more complicated. Eg using EnumWindows to know all HWND and then find out ProcessIDs by GetWindowThreadProcessId and then identify EXE and other stuff from WMI or further API calls. That'll make it possible to match ProcessID, EXE name, and HWND.

Bye, Olaf.


 
In german Windows, this would need to be oWSH.AppActivate("Unbenannt - Editor"), as that would be the caption of the notepad title bar of a new and yet unsaved file.

I would have thought so too. But even if the caption of the Notepad window is something like MyFile.txt - Notepad, my code will still work. I'm not sure I can explain why.

Where it might go wrong is if you have two instances of Notepad open. In that case, it seems to activate the instance that was previously activated, which might or might not be the one you want.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Well, I only had one Notepad instance and it didn't activate that. This is on Windows 10, perhaps it works on older Windows versions...

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top