Solved

Mouse events at XY on an automated IE object

Posted on 2002-04-25
10
1,588 Views
Last Modified: 2010-05-02
I control numerous instances of IE using automation (MS Internet Controls). In some SSL forms the objects 'clicked' do not have their names visible so it is hard to control them in code. Is there a way to set the mouse pointer to a given location on the IE object and 'click' on this point in code ?

Cheers !

Stewart
0
Comment
Question by:nvms
10 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 6968752
Private Declare Sub mouse_event Lib "user32" _
(ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)

Private Declare Function SetCursorPos Lib "user32.dll" (ByVal x As Long, ByVal y As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Const MOUSEEVENTF_ABSOLUTE = &H8000 '  absolute move
Private Const MOUSEEVENTF_LEFTDOWN = &H2 '  left button down
Private Const MOUSEEVENTF_LEFTUP = &H4 '  left button up

then to simulate a left click
SetCursorPos <x-coord>, <y-coord>
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0

Note: for winNT the mouse_event function has been superceded, use SendInput instead.
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6968756
also, you don't need the Sleep declare, this was just a section of code i've used.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6968765
This is an issue because you dont know if the IE window is maximized, if the button is even scrolled into view, etc.  Is there anything you can use to identify these buttons in the html?  Maybe you can rely on sourceindex?  Which index of the button it is if you loop through all the buttons on the form?
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:nvms
ID: 6970498
hmmmm well I can set the window state to maximised during the initation process so the location of the image I wish to click should be predicatable, assuming the author the doesn't change things around. In most cases the 'button' is a gif image and the code is hidden.

Appreciate greatly the dialogue. If Bobbit31's code (no relation to the famous eunich? :)  does the trick I finalise this query.

Deep thanks as always

Stewart Wood
0
 

Author Comment

by:nvms
ID: 6974636
That worked well, is there an equally simply process to send key strokes after a particular X,Y co-ordinate has been clicked ?  50 more points for the additional query...

Excellent watching my mouse pointer wander programatically over my desktop !

Stewart
0
 

Author Comment

by:nvms
ID: 6974676
That worked well, is there an equally simply process to send key strokes after a particular X,Y co-ordinate has been clicked ?  50 more points for the additional query...

Excellent watching my mouse pointer wander programatically over my desktop !

Stewart
0
 
LVL 18

Accepted Solution

by:
bobbit31 earned 150 total points
ID: 6977474
sure:

to send key strokes (using api):

Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Private Const KEYEVENTF_KEYUP = &H2
Private Const VK_CAPITAL = &H14

'' simply an example that presses caps lock
keybd_event VK_CAPITAL, 0, 0, 0
keybd_event VK_CAPITAL, 0, KEYEVENTF_KEYUP, 0

or you can use SendKeys:

ie:

'' press abcd
SendKeys "abcd"
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6986942
You could get a workaround at www.angelfire.com/realm/vb-shard/index.html
0
 

Author Comment

by:nvms
ID: 6991049
Thanks Mr Bobbit..... haven't tested it but i am sure it will work

Regards

Stewart
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6991568
no prob, glad to help!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

829 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