Hello, It's Isabel García from Barcelona and I am finding some problems with PostMessage method to send a mouse event to a web browser.
public void onClick2()
{
Process[] notepads = Process.GetProcessesByName("chrome");
if (notepads.Length == 0) return;
if (notepads[0] != null)
{
UnityEngine.Debug.Log("Encontrado");
hWnd = FindWindowEx(notepads[0].MainWindowHandle, new IntPtr(0), "Edit", null);
PostMessage(hWnd, MOUSEEVENTF_RIGHTDOWN, VK_RETURN, 0x001C0001);
PostMessage(hWnd, MOUSEEVENTF_RIGHTDOWN, VK_DOWN, 0x00500001);
}
}
The button in which I have to click has a unique id:
<a href="#" id="action-button" title="Share on WhatsApp" class="button button--simple button--primary">Send</a>
And I would like to access to that id. Using Spy++ I am not able to access to that button.
What I have tried:
I have used SendKeys but it has worked with Notepad app.
I have used Spy++ but without success with chrome web page.
I have perfom a click doing the following:
private const uint MOUSEEVENTF_MOVE = 0x0001;
private const uint MOUSEEVENTF_LEFTDOWN = 0x0002;
private const uint MOUSEEVENTF_LEFTUP = 0x0004;
private const uint MOUSEEVENTF_RIGHTDOWN = 0x0008;
private const uint MOUSEEVENTF_RIGHTUP = 0x0010;
private const uint MOUSEEVENTF_ABSOLUTE = 0x8000;
public void performClick(uint x, uint y)
{
mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTDOWN, x, y, 0, UIntPtr.Zero);
Thread.Sleep(200);
mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTUP, x, y, 0, UIntPtr.Zero);
UnityEngine.Debug.Log("performClick x: " + x + "y: "+ y);
}