Click to See Complete Forum and Search --> : Speed Problems
ChrisJackson
Nov 30th, 1999, 07:32 PM
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
Inhumanoid
Nov 30th, 1999, 08:18 PM
You could put the app to sleep by using API:
'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).]
ChrisJackson
Nov 30th, 1999, 08:48 PM
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
MartinLiss
Nov 30th, 1999, 09:27 PM
Try using DoEvents instead of Sleep. This will wait 1 second.
dim dblEndTime as Double
dblEndTime = Timer + 1#
Do While dblEndTime > Timer
' Do nothing but allow other
' applications to process
' their events.
DoEvents
Loop
------------------
Marty
ChrisJackson
Nov 30th, 1999, 09:48 PM
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
Serge
Nov 30th, 1999, 10:31 PM
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
Serge_Dymkov@vertexinc.com
Access8484@aol.com
ICQ#: 51055819 (http://www.icq.com/51055819)
Aaron Young
Dec 1st, 1999, 01:10 AM
The best you can do with ExecWB is to make the Save As.. Dialog Appear, eg.
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
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
aarony@redwingsoftware.com
adyoung@win.bright.net
ChrisJackson
Dec 1st, 1999, 11:34 AM
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
ChrisJackson
Dec 1st, 1999, 07:42 PM
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
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.