|
-
Oct 12th, 2003, 04:15 PM
#1
Thread Starter
Junior Member
Sendkeys
I need to know how I can have my VB application wait until something is open after a shell line before the SendKeys line activates.
thanks.
-
Oct 12th, 2003, 05:15 PM
#2
Different applications load differently. There is no 'finished loading' flag, meaning the best way to do what you want is to simply wait a specified amount of time before the SendKeys statement.
The time you enjoy wasting is not wasted time.
Bertrand Russell
<- Remember to rate posts you find helpful.
-
Oct 12th, 2003, 08:24 PM
#3
You can use the WaitForInputIdle function to get information when a process is ready to get input from the mouse or keyboard. However this function requires a hProcess handle which you don't get from the VB Shell function. You must eighter use CreateProcess or the ShellExecuteEx function.
I've written a wrapper sub that uses ShellExecuteEx to launch a file and then waits for the process to be ready to get input from the keyboard before it returns.
VB Code:
Private Declare Function ShellExecuteEx Lib "shell32.dll" (ByRef lpExecInfo As SHELLEXECUTEINFO) As Long
Private Declare Function WaitForInputIdle Lib "user32" (ByVal hProcess As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Type SHELLEXECUTEINFO
cbSize As Long
fMask As Long
hwnd As Long
lpVerb As String
lpFile As String
lpParameters As String
lpDirectory As String
nShow As Long
hInstApp As Long
' fields
lpIDList As Long
lpClass As Long
hkeyClass As Long
dwHotKey As Long
hIcon As Long
hProcess As Long
End Type
Private Const SEE_MASK_NOCLOSEPROCESS = &H40
Private Const SEE_MASK_FLAG_NO_UI = &H400
Public Sub ShellAndWaitForReady(ByVal sFile As String)
Dim hProcess As Long
Dim shi As SHELLEXECUTEINFO
Dim nRet As Long
shi.lpDirectory = vbNullString
shi.lpVerb = "Open"
shi.lpParameters = vbNullString
shi.lpFile = sFile
shi.nShow = vbNormalFocus
shi.fMask = SEE_MASK_FLAG_NO_UI Or SEE_MASK_NOCLOSEPROCESS
shi.cbSize = Len(shi)
If ShellExecuteEx(shi) > 32 Then
hProcess = shi.hProcess
Do
nRet = WaitForInputIdle(hProcess, 500)
DoEvents
Loop While nRet <> 0
CloseHandle hProcess
End If
End Sub
Just call ShellAndWaitForReady and pass it the file to launch (this could be either a program or a document that has an associated program).
Best regards
-
Oct 13th, 2003, 03:13 PM
#4
That's a really cool API, although it is very application specific. Better than my solution, though
The time you enjoy wasting is not wasted time.
Bertrand Russell
<- Remember to rate posts you find helpful.
-
Oct 13th, 2003, 04:00 PM
#5
Originally posted by jemidiah
That's a really cool API, although it is very application specific. Better than my solution, though
Application specific? Yes, it only works on Windows application and of course all application might not react to keyboard input even though it's ready to do so... but to that kind of application you can't use SendKeys anyway.
-
Oct 13th, 2003, 04:50 PM
#6
I tried it on Acrobat Reader 6, and it returned during the splash screen, which is why I said app. specific (mostly I was trying to insinuate they should, of course, test it on each app. they intended to use it on)
Last edited by jemidiah; Oct 13th, 2003 at 04:55 PM.
The time you enjoy wasting is not wasted time.
Bertrand Russell
<- Remember to rate posts you find helpful.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|