Results 1 to 9 of 9

Thread: Speed Problems

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Posts
    101

    Post

    Hi.

    My program mimics someone right-clicking and then pressing "V" using API. The problem that I am having is the processor works so fast, that the pressing of the "V" occurs before the right-click menu fully loads onto the screen. Therefore, it's like "V" isn't being pressed at all.

    How can I slow down the program so that this doesn't happen?

    Thanks.

    Chris

  2. #2
    Hyperactive Member
    Join Date
    Oct 1999
    Posts
    309

    Post

    You could put the app to sleep by using API:

    Code:
    'Declare
    Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    
    
    'formcode to make it sleep
    dim x as integer
    
    x = '# of sleep
    Call Sleep(x)
    [This message has been edited by Inhumanoid (edited 12-01-1999).]

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Posts
    101

    Post

    Inhumanoid, thanks for the reply but sleep didn't work. It pauses execution, but the "V" being pressed still isn't registering.

    Here's the code:

    Declare Sub mouse_event Lib "user32.dll" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
    Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

    Public Const MOUSEEVENTF_ABSOLUTE = &H8000
    Public Const MOUSEEVENTF_MOVE = &H1
    Public Const MOUSEEVENTF_RIGHTDOWN = &H8
    Public Const MOUSEEVENTF_RIGHTUP = &H10

    Public Const KEYEVENTF_KEYUP = &H2
    Public Const VK_V = &H56 'V

    Private Sub Command1_Click()
    WebBrowser1.Navigate "www.hotmail.com"
    End Sub

    Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    If pDisp Is WebBrowser1.Object Then
    mouse_event MOUSEEVENTF_MOVE Or MOUSEEVENTF_ABSOLUTE, 29000, 29000, 0, 0
    ' Press and then release the right mouse button.
    mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0
    mouse_event MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0

    Sleep (1000)

    ' Type the V key.
    keybd_event VK_V, 0, 0, 0 ' press V
    keybd_event VK_V, 0, KEYEVENTF_KEYUP, 0 ' release V
    End If

    Exit Sub

    ErrorHandler:
    MsgBox "Error " & Err.Number & " " & Err.Description
    End Sub


    Does anyone have any ideas?

    Thanks,

    Chris

    ------------------
    CJ

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    Try using DoEvents instead of Sleep. This will wait 1 second.
    Code:
        
        dim dblEndTime as Double
        dblEndTime = Timer + 1#
        Do While dblEndTime > Timer
          ' Do nothing but allow other
          ' applications to process
          ' their events.
          DoEvents
        Loop
    ------------------
    Marty

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Posts
    101

    Post

    Martin,

    Thanks for the reply.

    I put the code you provided into my project and the result was the same: the menu popped up, but pressing "V" wasn't registered.

    Did you run the code on your PC?

    I'm beginning to wonder if this can even be done. Please keep the ideas coming.

    Chris

  6. #6
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    Ohh, I see what you're trying to do. You want to get the source from the Web Page.
    Fortunately, you need only one line of code:

    WebBrowser1.Navigate2 "view-source:" & WebBrowser1.LocationURL

    ------------------

    Serge

    Software Developer
    [email protected]
    [email protected]
    ICQ#: 51055819


  7. #7
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    The best you can do with ExecWB is to make the Save As.. Dialog Appear, eg.
    Code:
    WebBrowser1.ExecWB OLECMDID_SAVEAS, OLECMDEXECOPT_DONTPROMPTUSER, "C:\SaveIt.htm", 0&
    There is a SubObject of the Webbrowser Document Object called DocumentElement from which you can extract the HTML from between the <HTML> Tags, e.g
    Code:
    Private Sub Command1_Click()
        Dim iFile As Integer
        iFile = FreeFile
        Open "C:\SaveIt.txt" For Output As iFile
            Print #iFile, "<HTML>" & WebBrowser1.Document.DocumentElement.InnerHtml & "</HTML>"
        Close iFile
    End Sub
    NB. This Object may only be available with IE4 or 5, Check the Document Object to see what's avaiable to you.

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Posts
    101

    Post

    Serge,

    Thanks for your response. I tried using the "view-source:" protocol previously, but I wasn't successful.

    Since trying to figure this problem out, I've discovered that you can get different results when you use different methods to retrieve the HTML source code of a web page. For example, if someone right-clicked and selected "View Source", the code displayed would be different from that returned using the view-source: statement on the particular web page that I've been working with.

    I know this seems strange, but it's true.

    It seems that the ExecWB statement could have done the trick, but I couldn't get it to automatically complete the steps to save the file.

    If anyone knows where I can get some documentation on ExecWB, I would appreciate it if they would share it.

    Thanks,

    Chris

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Posts
    101

    Post

    Thanks everyone for your help. Aaron, about ExecWB, like you stated I could get the "Save As" Dialog Box to appear and that's as far as I could go with it.

    I was able to get to the Source code of the Page by having my program "right-click" and then press "V" after some work in getting the "V" to register.

    Thanks again for all the suggestions.

    Chris

    ------------------
    CJ

Posting Permissions

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



Click Here to Expand Forum to Full Width