We help IT Professionals succeed at work.

Left Click on the specific part of the Screen.

Sandesh555
Sandesh555 asked
on
Hi Team,

Is it possible using program, that I can click on a specific part of the screen.  If yes, can I have a sample code to click on a specific part of the screen.

Please advise.
Comment
Watch Question

Top Expert 2011

Commented:
Can you be clearer on the usage, for example excel has hooks for cell change that potentially will work here.

Chris
well several ways you can do this In the attached file when you run it make sure your macros settings are set to Medium and enbale macros when prompt. just hoover the mouse on the form and see the X,Y location and the red dot following your mouse move. then click on hte option click and click anywhere on the userform and see the red dot move also this is an other way. Close the userform by pressing on the red X then right clik on any cell and it will insert the cell location where you clicked this is an other way in a worksheet to know where you clicked ...

So as chris mentioned tell us more your need we can probably better answer this.
showlocation.xls

Author

Commented:
Hi Team,

Thanks for your replied.

Basically I have to click on an radio button on a application, which does not get clicked using the Tab, as the radio button is not part of the tab sequency.  So I want to use mouse Click to click on the perticular radio button option.

The application here is a system based applicaton.

Regarding the attachment, I will check the same later and see if this answers my questions.

Author

Commented:
Hi gowflow,

I went though the file provided by you.  This is definetly informative, but I want to click on a application that is not an excel file.  This is a standalone application, installed on my laptop.

Thanks a lot for looking into ths.
pls post it if possible
gowflow

Author

Commented:
Sorry, I will not be able to post the screen shot.  As the application is confidicial in nature.  But to summarise.  I want to use Left Mouse Click outside of Excel VBA, using Excel VBA.

I have some basic understanding of coding.  Even if you can provide me a sample coding, that will help.
Top Expert 2011

Commented:
Personally I am still unclear, without knowledge of how or where the application of interest is we cannot advise.

For example if it's a vbs script then it will not trigger an excel event, whereas if it's an excel file then we can perhaps do something ... Therefore can you please be more specific about the application you are starting from?

Chris

Author

Commented:
Ok...

Let me take an example.  I dont want any even to control the click.  A macro has been designed in Excel VBA, whick fills up a user form from a differnt application.   Now most of the Data can be filled using SendKeys avaliable in Excel.

But I am not able to select a specific radio button using Sendkeys.  The radio button comes up in a specific part of the screen every time.   I just want to click on that radio button.

Does this answer your question.

Author

Commented:
In case you still dont understand, I will post a part of the screen shot by End of Day today.  As right now I dont have my Laptop with me.
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009

Commented:
You can click on a specific point on the screen using the mouse_event() or SendInput() APIs.

Getting the correct coords can be done in various ways.  Typically an absolute screen position is worthless as the user may move the window or resize the target app.  One approach is to get the top, left corner position of the main window with GetWindowRect() and then click at a fixed offset from that corner.  Another is to get a handle to the actual radiobutton window (if possible...it depends on what language the target app was written in) and then either click on its position or select it directly using the SendMessage() API.

Author

Commented:
Thanks.. Will explore the given functions... and in case of any question post back....

Author

Commented:
Hi,

Can you please give me a smal sample code for the mouse_even(), SendInput() and GetWindowRect().  So that I understand how to use them.  Or if you can also refer to some good website were I can read and understand how to use the same.

Thanks,
Sandesh.

Sandesh555
I don't know if I am missing somehting here, but I think I gave you example on how to use the mouse events in hte file I posted earlier which I am attaching once again.
gowflow

showlocation.xls
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009

Commented:
@gowflow...he's trying to manipulate an EXTERNAL application, not an internal Excel UserForm.
then he need to go API with hwnd to get handle of the application. Without hving the app running on your machine it will be quite difficult I guess to get the correct handles to intercept the application.
gowflow

Author

Commented:
Hi Team,

To simplify.  I will have sendkeys to select the specific application.   I will also place my move courser over the button that I want to be selected.

Now all I want in my coding is the VBA code we running.  It should just Left click on the location were the move courser is already positioned.
High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009
Commented:
Do something like...
Option Explicit

Private Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4

Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
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 Sub LeftClick(ByVal x As Long, ByVal y As Long)
    SetCursorPos x, y
    mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
    mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
End Sub

Open in new window