Mouse clicking

Craig

Well-known member
Joined
Oct 15, 2005
Messages
110
Location
United Kingdom
Programming Experience
Beginner
Is there a way in Visual Basic .NET to make it so the program will click in a certain position, without the user having to do it (obviously)

Thanks in advance.
 
So you mean to say that if you had button on the top left of the form and the pointer was at the bottom left for example, you want to be able to perform a click event on the button. If i have got the wrong end of the stick then could post back with some more detail?
 
It's not so hard to do. Just use the SendMessage or PostMessage API calls with PInvoke.
Although I must admit I can't think of a reason to do this.
VB.NET:
[COLOR=black][COLOR=blue]Private[/COLOR] [COLOR=blue]Const[/COLOR] WM_LBUTTONDOWN [COLOR=blue]As[/COLOR] Int32 = &H201
[COLOR=blue]Private[/COLOR] [COLOR=blue]Const[/COLOR] WM_LBUTTONUP [COLOR=blue]As[/COLOR] Int32 = &H202
[/COLOR]
 
<DllImport([COLOR=#800000]"user32.dll"[/COLOR])> _
[COLOR=#0000ff]Private [/COLOR][COLOR=#0000ff]Shared [/COLOR][COLOR=#0000ff]Function[/COLOR] SendMessage([COLOR=#0000ff]ByVal[/COLOR] hWnd [COLOR=#0000ff]As[/COLOR] IntPtr, [COLOR=#0000ff]ByVal[/COLOR] Msg [COLOR=#0000ff]As[/COLOR] Int32, _
[COLOR=#0000ff] ByVal[/COLOR] wParam [COLOR=#0000ff]As[/COLOR] Int32, [COLOR=#0000ff]ByVal[/COLOR] lParam [COLOR=#0000ff]As[/COLOR] Int32) [COLOR=#0000ff]As[/COLOR] IntPtr
[COLOR=#0000ff]End[/COLOR][COLOR=#0000ff] Function[/COLOR]
 
[COLOR=black][COLOR=blue]Private [/COLOR][COLOR=blue]Sub[/COLOR] simulateMouseClick([COLOR=blue]ByVal[/COLOR] handle [COLOR=blue]As[/COLOR] IntPtr, [COLOR=blue]ByVal[/COLOR] X [COLOR=blue]As[/COLOR] Int32, [COLOR=blue]ByVal[/COLOR] Y [COLOR=blue]As[/COLOR] Int32)
    [COLOR=blue]Dim[/COLOR] point [COLOR=blue]As[/COLOR] Int32 = Y << 16 [COLOR=blue]Or[/COLOR] X
    SendMessage(handle, WM_LBUTTONDOWN, 0, point)
    SendMessage(handle, WM_LBUTTONUP, 0, point)
[COLOR=blue]End[/COLOR] [COLOR=blue]Sub[/COLOR]
 
[COLOR=blue][COLOR=black][COLOR=blue]Private[/COLOR] [COLOR=blue]Sub[/COLOR] testMouseClicks()
    [COLOR=green]' Click on this form[/COLOR]
    simulateMouseClick(Handle, 13, 27)
     [COLOR=green]' Or: push a button[/COLOR]
     simulateMouseClick(ButtonClose.Handle, 0, 0)
[COLOR=blue]End[/COLOR] [COLOR=blue]Sub[/COLOR]
[/COLOR]
[/COLOR][/COLOR]
 
It's use is similar to PTFB Pro
Click here for info

PTFB Site said:
PTFB Pro is a mouse auto-clicker and macro recorder for automatically handling confirmation screens and other windows that interrupt your workflow. It quietly keeps watch from the system tray. When it sees a window that you have previously targeted, it carries out the button and key presses that you have defined, saving you time, irritation and finger-wear. PTFB Pro can also trigger your macros according to schedule, user-definable hot-key or command line directive.

Maybe I should have explained it is not going to be needed to click on the form

Thanks
 
Back
Top