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

vfp equivalent to wshshell.sendkeys

Status
Not open for further replies.

foxup

Programmer
Dec 14, 2010
328
CA
Hi,

Is there a VFP equivalent to wshshell.sendkeys?


Thanks,
FOXUP!
 
For one, you could call wshshell from foxpro. Also, you can use API of course:

Code:
DECLARE INTEGER keybd_event IN Win32API INTEGER, INTEGER, INTEGER, INTEGER 
* in short:
* 1st param: virtual key code (look into the MSDN docs) 
* 2nd param: press or release key. 
* as a sample this emulates pressing the PRINT key
keybd_event(44, 0, 0, 0) && press key
keybd_event(44, 0, 2, 0) && release key

Run this code, then star mspaint.exe and paste the screenshot.

[URL unfurl="true"]http://msdn.microsoft.com/en-us/library/ms927178.aspx[/URL]

You might also like autohotkey.

Bye, Olaf.
 
Hi Mike,

Nah, I'm actually looking for something that sends them 'out' to other apps.


thanks,
FOXUP!
 
In that case, Olaf's code might do the trick.

My preference would be to use the Windows Scripting Host. As an example, say you wanted to send some keystrokes to Notepad, you could do this:

Code:
oWsh = CREATEOBJECT("wscript.shell")

* Run Notepad
oWsh.Run("Notepad")

* Give Notepad a moment to load
WAIT TIMEOUT 0.5

* Type something into Notepad
oWsh.Sendkeys("Hello World")

You can also send special keys like ESC and TAB in this way, and modified keys like Alt+F1. The Windows Scripting Host documentation will give you the details.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Yes, as I said you can simply use wscrip shell from vfp. It also has the other ingredient to activate some app, AppActivate(). My sample API call is sending keys towards the active application. You can still use keybd_event in conjunction with hwnd=FindWindow() and SetForegroundWindow(hwnd) to activate the app you want to send keys to, if it's not a hotkey to the OS, like PRINT is.

see and
for sample code making use of these two API calls.

Autohotkey is also interesting, as it can generate EXEs from scripts that run without needing any particular runtime or installation, and it offers a huge amount of possibilities including running apps.


Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top