[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 282
  • Last Modified:

Click/doubleclick at a certain point on the screen through code

I was wondering if anyone knew how to write code that clicked/doubleclicked your mouse at a specific point on the screen.

Chris
0
khooc
Asked:
khooc
  • 4
  • 4
  • 3
2 Solutions
 
lee_ingramCommented:
what are you trying to do or achive? if i know this i can help your further
0
 
khoocAuthor Commented:
Hi Lee

I'm basically wanting to control the mouse, click/doubleclick/drag at certain parts of the screen.

Do you know how to do this?

Chris
0
 
lee_ingramCommented:
are you clicking or moving within your application or someone elses
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!

 
khoocAuthor Commented:
oh - anywhere.. it doesn't matter what app you're in...

basically, i want to tell the mouse to click at a certain position of the screen

I'm basically looking to create a tool for UI testing purposes

Chris
0
 
lee_ingramCommented:

OK,

The only way to do this as far a i know is to use mouse hooks, basically the same as a keyboard hook.

check out : http://support.microsoft.com/?kbid=318804
and http://www.codeproject.com/csharp/NetWin32Hooks.asp

both contain example code.  This should resolve your issue.

another source for a vb.net example is

http://www.vbcity.com/forums/faq.asp?fid=15&cat=Shell

hope this answers your question.

Lee
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You've got it backwards lee_ingram.  Hooks would be used to track the mouse movements/clicks no matter where they occur.

Here is an example of left clicking at a specific point:

Public Class Form1
    Inherits System.Windows.Forms.Form

    Private Declare Sub mouse_event Lib "user32" _
        (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, _
        ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)

    Public Const MOUSEEVENTF_LEFTDOWN As Integer = &H2
    Public Const MOUSEEVENTF_LEFTUP As Integer = &H4
    Public Const MOUSEEVENTF_MIDDLEDOWN As Integer = &H20
    Public Const MOUSEEVENTF_MIDDLEUP As Integer = &H40
    Public Const MOUSEEVENTF_RIGHTDOWN As Integer = &H8
    Public Const MOUSEEVENTF_RIGHTUP As Integer = &H10

    Private Sub LeftClick(ByVal x As Integer, ByVal y As Integer)
        Cursor.Position = New Point(x, y)
        mouse_event(MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
    End Sub

End Class


0
 
lee_ingramCommented:
Idle_Mind you need to read all the comments before jumping in mate ;-)

This is actually what he wanted.  He wanted to beable to recieve mouse events not only for his application but for other applications aswell. He also want to move the mouse etc not just recieve clicks and location.

QUOTE:

"oh - anywhere.. it doesn't matter what app you're in...

basically, i want to tell the mouse to click at a certain position of the screen

I'm basically looking to create a tool for UI testing purposes"
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
I have to disagree...

My interpretation of his statements:

    "oh - anywhere.. it doesn't matter what app you're in...
    basically, i want to tell the mouse to click at a certain position of the screen
    I'm basically looking to create a tool for UI testing purposes"

Is that he wants to be able to programmatically move and/or click the mouse anywhere on the screen, regardless of whether that point is within his application or not, for the purpose of testing some application at that point.

From the second line, he wants to "tell" (or "control" from his previous post) the mouse to move/click at a "certain position of the screen".  These are active words...which to me says he doesn't want to receive mouse events, but instead wants to send them.

I'm sure khooc will let us know what interpretation is correct.  Let's wait and see...
0
 
khoocAuthor Commented:
Hi guys

Apologies for the miscommunication... I'll go to my English class now..

I was actually after Idle_Mind's answer, but Lee - your answer is also very useful :-) so points to both.

Chris
0
 
khoocAuthor Commented:
...
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now