How could I modify this code to be able to click anywhere on the screen?

  • Thread starter Thread starter Germo_Keys
  • Start date Start date
G

Germo_Keys

Guest
Hello! How are you? I hope it's okay :)

Well, my question is this, I am trying to make an automation system and I need to complete the task with the mouse and I found this code created by: Martin_Xie.
Well, the code works well, fulfills its function but only reads the coordinates inside the form, but in external applications it does not work, so I would like it to work on the whole screen, that is, its form, in any application outside of its form.
This is the code:

Imports System.Runtime.InteropServices



Public Class Form1



<DllImport("user32.dll")> _

Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByRef lParam As IntPtr) As IntPtr

End Function



<DllImport("user32.dll")> _

Shared Function WindowFromPoint(ByVal pnt As Point) As IntPtr

End Function



Const BM_CLICK As Integer = &HF5&



Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Timer1.Enabled = True

Timer1.Interval = 1000

End Sub



Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

' Dim pnt As Point = Me.PointToScreen(Button1.Location)

Dim pnt As Point = New Point(10, 10) ' Specify the location where you want to click.

Dim hWnd As IntPtr = WindowFromPoint(pnt)

If hWnd <> IntPtr.Zero Then

SendMessage(hWnd, BM_CLICK, 0, IntPtr.Zero)

' SendMessage(Me.Button1.Handle, BM_CLICK, 0, IntPtr.Zero)

End If



End Sub

End Class
grace for the time given

Continue reading...
 
Back
Top