Solved

Sending keystrokes to a shelled APP

Posted on 1998-12-13
1
134 Views
Last Modified: 2010-05-03
I am trying to shell an application then send key strokes to it. The problem is, I try to shell it so it is openned minimized with focus. And then when I use the send key funtion, it doesn't work.
0
Comment
Question by:mjh2
1 Comment
 
LVL 12

Accepted Solution

by:
mark2150 earned 70 total points
Comment Utility
You need to open it maximized or normal with focus. Also use an AppActivate just prior to sending it keys and put a DoEvents before and after the SendKeys command. Here is the routine I use to drive external programs with good success:

Public retval As Double     'Spawned child ID

' Launch child task, gotta be visible!

retval = Shell(ChildTaskPath, vbMaximizedFocus)

' Sample call to child task

sendit ("%FO" & FileName & "{enter}")
Call delay(3)

' Subroutine that sends data to child task

Private Sub sendit(txt As String)
'
' Send string to child task
'
    On Error Resume Next
    AppActivate retval      'Make sure child task is active
    DoEvents                'Give it a shot to run
    SendKeys txt, True      'Tell it what to do and wait
    DoEvents                'Cede some more time
'
End Sub

' Delay loop to give child app time to breathe

Private Sub delay(secs As Integer)
'
' Sanity check passed param
'
secs = Abs(secs)
If secs > 100 Then secs = 100
'
' Pass delay value and diddle here until time expires
'
etime = Timer + secs
Do While Timer < etime
    DoEvents
Loop
'
End Sub

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now