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

SendKeys

Status
Not open for further replies.

LCD

MIS
Feb 19, 2001
72
US
I'm having a issue with the following Code. SendKeys DOES work, but only 15% of the time. Is there a more stable way to send keys to another program?
-----------------------------------------------
Private Sub Command1_Click()
Dim RetVal
RetVal = Shell("C:\SomeDIR\Some.exe", 4)
End Sub

Private Sub Command2_Click()
AppActivate "SomeProgram", True
SendKeys "%S", True
End Sub
-----------------------------------------------
Thank you,
Andrew



*************************************
* Help stop the CBDTPA Bill from becoming law *
* Please visit and *
* *
*************************************
 
Pass it to the other program as a parameter. i.e.
[tt]
Private Sub Command1_Click()
Dim RetVal
RetVal = Shell("C:\SomeDIR\Some.exe %S", 4)
End Sub
[/tt]
Then in the SomeEXE program have this on the form load.
[tt]
Dim strParam As String
strParam = Command()

'Do stuff with yoru param
Select Case strParam
Case = "S"

Case Else

End Select
[/tt]
Craig, mailto:sander@cogeco.ca

Remember not to name the Lambs...
It only makes the chops harder to swallow
 
If the program ttahe you want to SendKeys to is the same one that you SHELLed to then save the return value fron the SHELL and use it in the AppActivate.
' Form Level
Private dblSHELLRet As Variant

Private Sub Command1_Click()
dblSHELLRet = Shell("C:\SomeDIR\Some.exe", 4)
End Sub

Private Sub Command2_Click()
AppActivate dblSHELLRet, True
SendKeys "%S", True
End Sub

From the Docs.
"AppActivate title[, wait]

The AppActivate statement syntax has these named arguments:

Part Description
title Required. String expression specifying the title in the title bar of the application window you want to activate. The task ID returned by the Shell function can be used in place of title to activate an application. "
Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
The AppActivate function works, I can see the other program gain focus. But after it obtains focus, it does not recieve the SendKeys statement. (It does recieve the sendkeys randomly (ie 1 out of every 6 clicks will actualy work)).
Unfortunatly I dont have the source for the program i'm sending to.
I appreciate the help, thank you.
Andrew



*************************************
* Help stop the CBDTPA Bill from becoming law *
* Please visit and *
* *
*************************************
 
I think I solved my problem. FYI(timer1.Interval = 100)
-----------------------------------------------
Dim RetVal As Variant

Private Sub Command1_Click()
RetVal = Shell("C:\SomeDIR\SomeProgram.exe", 4)
End Sub

Private Sub Command2_Click()
AppActivate RetVal, True 'By Giving the program Focus
Timer1.Enabled = True 'And then a slight pause
End Sub 'before SendKeys

Private Sub Timer1_Timer()
SendKeys "%S", True
Timer1.Enabled = False
End Sub
---------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top