Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Mouse events at XY on an automated IE object

Posted on 2002-04-25
10
Medium Priority
?
1,698 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 600 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

916 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