Solved

Mouse events at XY on an automated IE object

Posted on 2002-04-25
10
1,532 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
 

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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
VB6 convert MSHFlexgrid1 cells 7 52
Use Multiple Forms 4 38
Vb.net 2008 2 49
vb6 - Transfer from MSHFlexgrid1 to xls issue 8 13
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now