I created a windows form and added two buttons and a browser in the form. I used a program to get the mouse coordinates and click a login button. I would like to implement this without moving the cursor. I am not looking to find the login button ID or use HTML request/response.
Any idea if it is possible to click non html button in a browser without moving the cursor.
This code below works but only for other controls within the form but not for the browser that is part of the form
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace simulateclicktest
{
public partial class Form1 : Form
{
[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int Msg,
IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", EntryPoint = "WindowFromPoint",
CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr WindowFromPoint(Point point);
private const int BM_CLICK = 0x00F5;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// Specify the point you want to click
var screenPoint = new Point(157
,455);
// Get a handle
var handle = WindowFromPoint(screenPoint);
// Send the click message
if (handle != IntPtr.Zero)
{
SendMessage(handle, BM_CLICK, IntPtr.Zero, IntPtr.Zero);
}
}
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("clicked");
}
}
}