Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2003
    Posts
    45

    Unanswered: sendkeys Statment

    how can I use SendKeys statment to open aprogram and wait until the program Initializes and then send anothe sendkeys Statment to do othe thing on the opened progrma?
    for example:
    1- sendKeys to open document scanning program.
    2- wait until it intializes.
    3- sendKeys to start new scan
    4- wait until finish scaning
    5- send keys to save the image

  2. #2
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    The key to your problem is the waiting. With Access and SendKeys you will either have to wait a specific time (ex. 2 minutes, 2 seconds, 5 hours) or use some indicator to tell when a step is done.

    With scanning is a file created? You could loop and check to see if the file was created. The problem with this is usually the file is added to the directory structure but the file has not been completely written.

    Another possibility is sending all the commands at once and seeing if they all get buffered. Then the program that is scanning and copying can 'interpret" what all the keys should do.

    More often than not I have to do the timing thing. Open the program, wait x seconds, sendkeys, wait x minutes, etc. Usually there is a lot of wasted time and it only works about 80% of the time.

  3. #3
    Join Date
    Sep 2005
    Location
    Bay Area CA
    Posts
    15
    With C/C++ you can use a callback function - don't know how to do it in VBA, but you would use the API sendmessage function...

  4. #4
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    You might find this useful:

    Code:
    Option Compare Database
    
    
    
    '***************** Code Start ******************
    'This code was originally written by Terry Kreft.
    'It is not to be altered or distributed,
    'except as part of an application.
    'You are free to use it in any application,
    'provided the copyright notice is left unchanged.
    '
    'Code Courtesy of
    'Terry Kreft
    Private Const STARTF_USESHOWWINDOW& = &H1
    Private Const NORMAL_PRIORITY_CLASS = &H20&
    Private Const INFINITE = -1&
    
    Public Type STARTUPINFO
        cb As Long
        lpReserved As String
        lpDesktop As String
        lpTitle As String
        dwX As Long
        dwY As Long
        dwXSize As Long
        dwYSize As Long
        dwXCountChars As Long
        dwYCountChars As Long
        dwFillAttribute As Long
        dwFlags As Long
        wShowWindow As Integer
        cbReserved2 As Integer
        lpReserved2 As Long
        hStdInput As Long
        hStdOutput As Long
        hStdError As Long
    End Type
    
    Public Type PROCESS_INFORMATION
        hProcess As Long
        hThread As Long
        dwProcessID As Long
        dwThreadID As Long
    End Type
    
        
    Public Sub ShellWait(Pathname As String, Optional WindowStyle As Long)
        Dim proc As PROCESS_INFORMATION
        Dim start As STARTUPINFO
        Dim ret As Long
        ' Initialize the STARTUPINFO structure:
        With start
            .cb = Len(start)
            If Not IsMissing(WindowStyle) Then
                .dwFlags = STARTF_USESHOWWINDOW
                .wShowWindow = WindowStyle
            End If
        End With
        ' Start the shelled application:
        ret& = CreateProcessA(0&, Pathname, 0&, 0&, 1&, _
                NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
        ' Wait for the shelled application to finish:
        DoEvents
        ret& = WaitForSingleObject(proc.hProcess, INFINITE)
        ret& = CloseHandle(proc.hProcess)
    End Sub
    '***************** Code End ****************
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  5. #5
    Join Date
    Oct 2003
    Posts
    45
    Thanks for evry one tryed to help, I will do my best to solve the problem as you sugested.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •